转换秒整数到HH:MM,iPhone

编程入门 行业动态 更新时间:2024-10-19 20:22:09
本文介绍了转换秒整数到HH:MM,iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在为此苦苦挣扎。我希望以HH:MM格式在标签中显示秒数。我在互联网上搜索了很多年,发现了一些答案,但是要么没有完全理解它们,要么他们看起来像是一种奇怪的做我想做的事情的方式。如果有人能帮助我,这将是伟大的!请记住,我是这个游戏的新手,所以这个问题可能看起来像一个真正的基本到那里更有经验的人。

解决方案

我正在寻找同样的东西,你正在寻找,但无法找到一个。所以我写了一个 - $ / $ b $ pre $ - (NSString *)timeFormatted:(int)totalSeconds { int seconds = totalSeconds%60; int分钟=(totalSeconds / 60)%60; int hours = totalSeconds / 3600; return [NSString stringWithFormat:@%02d:%02d:%02d,hours,minutes,seconds];

在 Swift p>

func timeFormatted(totalSeconds:Int) - >字符串{ let seconds:Int = totalSeconds%60 let minutes:Int =(totalSeconds / 60)%60 let hours:Int = totalSeconds / 3600 return String :%02d:%02d:%02d,小时,分钟,秒)}

I am struggling with this. I have a value in seconds that I want to display in a label in HH:MM format. I have searched the internet for ages and found some answers, but either not fully understood them, or they seem like an odd way of doing what I want. If someone could help me out on this one that would be great! Bear in mind that I am new to this games so this question may seem like a really basic one to the more experienced out there.

解决方案

I was looking for the same thing that you are looking but couldn't find one. So I wrote one -

- (NSString *)timeFormatted:(int)totalSeconds { int seconds = totalSeconds % 60; int minutes = (totalSeconds / 60) % 60; int hours = totalSeconds / 3600; return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds]; }

works perfectly in Swift as well:

func timeFormatted(totalSeconds: Int) -> String { let seconds: Int = totalSeconds % 60 let minutes: Int = (totalSeconds / 60) % 60 let hours: Int = totalSeconds / 3600 return String(format: "%02d:%02d:%02d", hours, minutes, seconds) }

更多推荐

转换秒整数到HH:MM,iPhone

本文发布于:2023-11-30 09:38:02,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   HH   iPhone   MM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!