NSDate 获得时间

NSDateFormatter * formatter = [[NSDateFormatter alloc]init];

    [formatter setDateFormat:@"yyyy-MM-dd-hh:mm:ss"];

    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];

    NSDate * date = [NSDate date];

    NSString * timeNow = [formatter stringFromDate:date];

    NSLog(@"timeNow %@", timeNow);//2016-03-22-01:23:39

    

    //格林威治时间 10   1458624241

    UInt64 recordTime0 = [[NSDate date] timeIntervalSince1970];

    

    //格林威治时间 毫秒13 1458624284282

    UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000;

    

    

    //格林威治时间,8个小时 2016-03-22 05:26:22 +0000

    NSDate * date22 = [NSDate date];

    NSLog(@"date22 %@",date22); //格林威治时间,8个小时

    

    

    //中国时间毫秒 1458653287948  13

    UInt64 time = ([[NSDate date] timeIntervalSince1970]+28800)*1000;

    NSLog(@"time %llu", time);

    

    //精确到小数点后6 1458653335251.256836

    double recordTime13 = ([[NSDate date] timeIntervalSince1970]+28800)*1000.0;

    NSLog(@"recordTime13 %f", recordTime13);

    

    

    //毫秒转日期 2016-03-22 13:28:07 +0000

    NSDate *d = [[NSDate alloc]initWithTimeIntervalSince1970: time/1000

                 ];

    NSLog(@"d %@", d);//2016-03-22 13:19:32 +0000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值