iOS开发 时间秒数转天小时分钟 oc代码
以下是一个将时间秒数转换为天、小时和分钟的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分钟"。
原文地址: https://www.cveoy.top/t/topic/ixoQ 著作权归作者所有。请勿转载和采集!