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

iOS开发 秒数转时分秒 oc代码

原文地址: http://www.cveoy.top/t/topic/jbs7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录