//将时间戳按yyyy-MM-dd HH:mm:ss格式时间输出,并加上时区偏移
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
NSLog(@"++ %@", datenow);
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
//将时间戳按yyyy-MM-dd HH:mm:ss格式时间输出,并加上时区偏移
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:dateNum.floatValue];
NSLog(@"1296035591 = %@",confromTimesp);
NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
NSLog(@"confromTimespStr = %@",confromTimespStr);
//将时间戳转换成NSDate,加上时区偏移
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[dateNum intValue]];
NSLog(@"the date is %@", confromTimesp);
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:confromTimesp];
NSLog(@"interval is %ld", (long)interval);
NSDate *localDate = [confromTimesp dateByAddingTimeInterval:interval];
NSLog(@"the localDate is %@", localDate);