iOS时间戳与标准时间转换

生成当前时间的时间戳

NSString * timestamp = [NSString stringWithFormat:@"%ld",time(NULL)];

将时间戳转换成标准时间

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate * currentDate = [NSDate dateWithTimeIntervalSince1970:[timestamp longLongValue]];
NSString * formDateStr = [formatter stringFromDate:currentDate];
NSLog(@"当前时间:%@",formDateStr);





展开阅读全文

没有更多推荐了,返回首页