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

 

//转换成时分秒

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

posted @ 2016-08-05 12:01  SoulDu  阅读(8426)  评论(0编辑  收藏  举报