美文网首页
秒转换成时分秒

秒转换成时分秒

作者: AnderQZ | 来源:发表于2017-03-08 18:41 被阅读103次
    #import <Foundation/Foundation.h>
    

    int main(int argc, const char * argv[]) {
    @autoreleasepool {
    // insert code here...
    NSString *totalTime = @"5430";
    NSInteger seconds = [totalTime integerValue];

        //format of hour
        NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600];
        //format of minute
        NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];
        //format of second
        NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];
        //format of time
        NSString *format_time = [NSString stringWithFormat:@"%@:%@:%@",str_hour,str_minute,str_second];
        
        NSLog(@"Time: %@",format_time);
    }
    return 0;
    

    }

    相关文章

      网友评论

          本文标题:秒转换成时分秒

          本文链接:https://www.haomeiwen.com/subject/bgfigttx.html