NS秒数到小时,分钟,秒 [英] NSNumber of seconds to Hours, minutes, seconds
问题描述
我有一个可怕的时间试图做一些应该很容易的事情。我有一个NSNumber值32025.89秒。我需要在小时,分钟,秒表示。有没有一种方法吐出来?我似乎找不到一个合适的格式化。
您尝试从中创建 NSDate
NSDateFormatter
?
NSDate * date = [NSDate dateWithTimeIntervalSince1970: doubleValue]];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@HH:mm:ss];
NSLog(@%@,[formatter stringFromDate:date]);
[formatter release];
如果您需要小时,分钟和秒的单个值,请使用 如果 I am having a terrible time trying to do something that should be easy. I have a NSNumber value of 32025.89 seconds. I need to represent that in Hours, Minutes, Seconds. Is there a method that spits that out? I can't seem to find a proper formatter. Have you tried creating an If you need the individual values for hours, minutes, and seconds, use The above won't print the correct amounts if the 这篇关于NS秒数到小时,分钟,秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
NSNumber $ c>,上面的命令不会输出正确的金额$ c>表示超过一天。它可以是1天和1小时,它只打印01:00:00。在这种情况下,您应该手动计算小时,分钟和秒钟。
NSDate
from that and printing that using an NSDateFormatter
?NSDate *date = [NSDate dateWithTimeIntervalSince1970:[theNumber doubleValue]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss"];
NSLog(@"%@", [formatter stringFromDate:date]);
[formatter release];
NSDateComponents
as suggested by nall.NSNumber
represents more than one day. It could be 1 day and 1 hour, and it would only print 01:00:00. In such a case you should calculate hours, minutes and seconds manually.