首页 > 移动平台 > 详细

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

时间:2016-08-05 13:54:45      阅读:450      评论:0      收藏:0      [点我收藏+]

 

//转换成时分秒

- (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);
}

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

原文:http://www.cnblogs.com/soulDn/p/5740790.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!