iOS开发:秒数转换为时分秒的OC代码实现
-
(NSString *)timeFormatted:(NSInteger)totalSeconds { NSInteger seconds = totalSeconds % 60; NSInteger minutes = (totalSeconds / 60) % 60; NSInteger hours = totalSeconds / 3600;
return [NSString stringWithFormat:'%02ld:%02ld:%02ld', (long)hours, (long)minutes, (long)seconds]; }
使用示例:
NSInteger totalSeconds = 3661; NSString *formattedTime = [self timeFormatted:totalSeconds]; NSLog(@'%@', formattedTime);
输出结果为:01:01:01
原文地址: https://www.cveoy.top/t/topic/hWDB 著作权归作者所有。请勿转载和采集!