iOS

iOS 秒数转换成时间,时,分,秒

2018-08-12  本文已影响1760人  淋雨no2

//转换成时分秒

- (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 *)timeFormatted:(int)totalSeconds

{

NSDate  *date = [NSDate dateWithTimeIntervalSince1970:totalSeconds];

NSTimeZone *zone = [NSTimeZone systemTimeZone];

NSInteger interval = [zone secondsFromGMTForDate: date];

NSDate *localeDate = [date  dateByAddingTimeInterval: interval];

NSLog(@"enddate=%@",localeDate);

}

上一篇下一篇

猜你喜欢

热点阅读