格式化字符串有什么捷径吗?

发布于 2024-09-16 05:07:51 字数 215 浏览 3 评论 0原文

我正在使用目标c,并且我得到了一些像这样的变量:

1100
920
845
1439

但我想将其更改为:

11:00 
09:20
08:45
14:39

问题是当我只得到三个数字时如何填充零?我知道逻辑可以很简单,我检测字符串长度,但是有什么方法可以更有效地做到这一点吗?谢谢。

I am using objective c, and I got some variables like this:

1100
920
845
1439

But I want to change it to :

11:00 
09:20
08:45
14:39

The problem is how can I fill the zero when I got three number only? I know the logic can be simple to do it I detect the string length, but is there any way to do it more effectually? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美的太阳 2024-09-23 05:07:51
unsigned int time = 1100;

NSString *strTime = [NSString stringWithFormat:@"%02u:%02u", time / 100, time % 100];
unsigned int time = 1100;

NSString *strTime = [NSString stringWithFormat:@"%02u:%02u", time / 100, time % 100];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文