本文主要是介绍IOS 秒数转换为天数和小时数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
获取时间字符串,然后根据“-”将其分开,数组一是时间值,数组二是时间值的颜色。
NSString *tempStr = [self getOvertime:time];NSArray *tempArray = [tempStr componentsSeparatedByString:@"-"];_dataStr = [tempArray objectAtIndex:0];NSString *_colorType = [tempArray objectAtIndex:1];
//将时间数据(毫秒)转换为天和小时
- (NSString*)getOvertime:(NSString*)mStr
{long msec = [mStr longLongValue];if (msec <= 0){return @"";}NSInteger d = msec/1000/60/60/24;NSInteger h = msec/1000/60/60%24;//NSInteger m = msec/1000/60%60;//NSInteger s = msec/1000%60;NSString *_tStr = @"";NSString *_dStr = @"";NSString *_hStr = @"";NSString *_hTimeType = @"defaultColor";if (d > 0){_dStr = [NSString stringWithFormat:@"%ld天",d];}if (h > 0){_hStr = [NSString stringWithFormat:@"%ld小时",h];}//小于2小时 高亮显示if (h > 0 && h < 2){_hTimeType = @"hightColor";}_tStr = [NSString stringWithFormat:@"%@%@后到期-%@",_dStr,_hStr,_hTimeType];return _tStr;
}
这篇关于IOS 秒数转换为天数和小时数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!