【问题标题】:Convert seconds to formatted time like 12:59? [duplicate]将秒转换为格式化时间,如 12:59? [复制]
【发布时间】:2011-06-06 12:53:20
【问题描述】:

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

如何在 Objective-C 中做到这一点

例如:
349200秒??

【问题讨论】:

标签: iphone objective-c ipad nsdate nsdateformatter


【解决方案1】:

添加以下函数并在此函数中传递“秒”值。

- (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 是标签。

【讨论】:

  • 嗨,现在查看函数。它将给出小时、分钟和秒。干杯。
猜你喜欢
  • 2011-04-20
  • 2013-10-19
  • 2019-07-04
  • 1970-01-01
  • 2021-01-28
  • 2013-08-27
  • 2014-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多