将秒转换为格式化时间,如12:59?

时间:2011-06-06 12:53:21

标签: iphone objective-c ipad nsdate nsdateformatter

  

可能重复:
  Convert seconds to days, minutes, and hours in Obj-c

如何在Objective-C

中完成

例如:
349200秒??

1 个答案:

答案 0 :(得分:10)

添加以下功能并在此功能中传递“秒”值。

- (void)displayTimeWithSecond:(NSInteger)seconds   
        {  
        NSInteger remindMinute = seconds / 60;
NSInteger remindHours = remindMinute / 60;

NSInteger remindMinutes = seconds - (remindHours * 3600);
NSInteger remindMinuteNew = remindMinutes / 60;

NSInteger remindSecond = seconds - (remindMinuteNew * 60) - (remindHours * 3600);

NSLog(@"Hours = %@", [NSString stringWithFormat:@"%02d",remindHours]);
NSLog(@"Minute = %@", [NSString stringWithFormat:@"%02d",remindMinuteNew]);
NSLog(@"Seconds = %@", [NSString stringWithFormat:@"%02d",remindSecond]); 
}

这里,displayTime是Label。

相关问题