[iOS]时间戳与时间(NSDate)的相互转化
时间戳又称为UNIX时间戳(Unix timestamp),定义从格林威治时间1970年1月1日00时00分00秒起到现在的总秒数。一些服务器接口返回的时间会使用时间戳。
一、时间戳转化为时间(NSDate)
NSDate * localDate = [NSDate date]; NSString * timeStamp = [NSString stringWithFormat:@"%ld", (long)[localDate timeIntervalSince1970]];
二、时间(NSDate)转化为时间戳
NSDate *currentTimestamp = [NSDate dateWithTimeIntervalSince1970:1437009380];