把秒转换成时分秒: - (NSString *)timeFormatted:(int)totalSeconds{ int seconds = totalSeconds % 60; int minutes = (totalSeconds / 60) % 60; int hours = totalSeconds / 3600; return [NSString stringWithFormat:@"%02d:%02d:%02d",hours,
把秒转换成时分秒:
- (NSString *)timeFormatted:(int)totalSeconds
{
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
}
把毫秒转换成时间格式:
//将时间数据(毫秒)转换为天和小时
- (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;
}
作者:稻草人11223
【文章出处:日本大带宽服务器 http://www.558idc.com/jap.html 欢迎留下您的宝贵建议】