iOS 将服务器返回的时间戳转换成特定时区的时间
2017-07-17 本文已影响18人
AlanAnie
#pragma mark - 将时间戳转化成某个时间
- (NSString *)getNowTimestamp:(NSNumber *)timerNumber{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"YYYYMMddHHmm"];
/* 设置时区 */
NSTimeZone *systemZone = [NSTimeZone systemTimeZone];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[dateFormatter setTimeZone:timeZone];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[timerNumber longLongValue]];
NSString *dateString = [dateFormatter stringFromDate:date];
//dateString = [dateString substringToIndex:20];
return dateString;
}
这里我是以亚洲上海时间为转化