ios 时间戳 与 时间相互转化

1.今天在作一个webservice的接口的时候,被要求传一个时间戳过去,而后就是开始在Google上找 web

2.遇到两个问题,一,当前时间转化为时间戳,二,获取的当前时间和系统的时间相差8个小时 spa

一,转化的方法为 orm

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

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


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

 NSDate *datenow = [NSDate date];//如今时间,你能够输出来看下是什么格式 it

    NSTimeZone *zone = [NSTimeZone systemTimeZone]; date

    NSInteger interval = [zone secondsFromGMTForDate:datenow]; service

    NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval]; 方法

    NSLog(@"%@", localeDate);


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

    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];

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


4.完成

相关文章
相关标签/搜索