我的秒数是 54000。我怎样才能得到下午 3:00:00 的时间?
我可以使用任何日期格式化程序来获取它吗?
谢谢
假设给定的秒数在本地时区,并且您想要转换为本地时区。
NSInteger timeInSeconds = 54000;
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:timeInSeconds]];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"hh:mm:ss a"];
NSString *dateString = [formatter stringFromDate:date];
假设您希望在“正常”日期(即没有时区更改的日期)根据当前区域设置格式化时间,
double seconds = 54000;
NSDateFormatter * fmt = [NSDateFormatter new];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:seconds];
NSString * s = [fmt stringFromDate:date];
// If you are not using ARC,
[fmt release];