iOS开发 秒数转时分秒字符串 oc代码
以下是一个将秒数转换为时分秒字符串的OC代码示例:
- (NSString *)convertSecondsToTimeString:(NSInteger)seconds {
NSInteger hour = seconds / 3600;
NSInteger minute = (seconds % 3600) / 60;
NSInteger second = (seconds % 3600) % 60;
NSString *timeString = [NSString stringWithFormat:@"%02ld:%02ld:%02ld", (long)hour, (long)minute, (long)second];
return timeString;
}
使用示例:
NSInteger seconds = 3665;
NSString *timeString = [self convertSecondsToTimeString:seconds];
NSLog(@"%@", timeString); // 输出:01:01:05
在这个示例中,我们将秒数3665传递给convertSecondsToTimeString方法,该方法将秒数转换为时分秒字符串并返回。输出结果为01:01:05
原文地址: http://www.cveoy.top/t/topic/ilE5 著作权归作者所有。请勿转载和采集!