码迷,mamicode.com
首页 > 其他好文 > 详细

时间戳

时间:2015-05-24 12:46:15      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

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

    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];   

//    1

    NSDate *date = [NSDate date];

    NSLog(@"时间  %@",[formatter stringFromDate:date]);      

    NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[[formatter dateFromString:[formatter stringFromDate:date]] timeIntervalSince1970]];

    NSLog(@"---timeSP---- %@ ",timeSp);

//    2

    NSTimeInterval time=[timeSp doubleValue];

    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];

    NSLog(@"date:%@",[detaildate description]);    

    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timeSp doubleValue]];

    NSLog(@"1296035591  = %@",confromTimesp);

    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];

    NSLog(@"confromTimespStr =  %@",confromTimespStr);

时间戳

标签:

原文地址:http://www.cnblogs.com/lyl-/p/4525590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!