时间戳和当前时间互相转化

1,转化的方法为

 

    NSString *timeSp = [NSStringstringWithFormat:@"%d", (long)[localeDate timeIntervalSince1970]];

    NSLog(@"timeSp:%@",timeSp); //时间戳的值

 

2,把获取的时间转化为当前时间

 

 NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式

    NSTimeZone *zone = [NSTimeZone systemTimeZone];

    NSInteger interval = [zone secondsFromGMTForDate:datenow];

    NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval];

    NSLog(@"%@", localeDate);

 

3.把时间戳转化为时间的方法

 

    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];

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

 

4.完成

posted @ 2014-02-12 20:43  shaneZhang  阅读(260)  评论(0编辑  收藏  举报