我正在寻找同样的东西,你正在寻找,但无法找到一个。所以我写了一个 - $ / $ 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
发布评论