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

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

你可以在需要将时间转换为天、小时和分钟的地方调用这个方法。传入的参数是时间的秒数,返回的是转换后的字符串,例如'2天 4小时 30分钟'。

iOS 开发:秒数转换为天、小时、分钟 (OC 代码示例)

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

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