以下是一个将时间秒数转换为天、小时、分钟的Objective-C代码示例:

- (NSString *)convertSecondsToDHM:(NSInteger)seconds {
    NSInteger days = seconds / (60 * 60 * 24);
    NSInteger hours = (seconds / (60 * 60)) % 24;
    NSInteger minutes = (seconds / 60) % 60;
    
    NSString *result = [NSString stringWithFormat:@'%ld天 %ld小时 %ld分钟', (long)days, (long)hours, (long)minutes];
    return result;
}

使用示例:

NSInteger timeInSeconds = 123456;
NSString *timeString = [self convertSecondsToDHM:timeInSeconds];
NSLog(@'%@', timeString);

输出结果:

1天 10小时 17分钟
iOS开发:Objective-C代码将秒数转换为天、小时、分钟

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

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