NSDate:5是坑啊啊!
1 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 2 3 [dateFormatter setDateFormat:@"yyyy/MM/dd hh:mm:ss"]; 4 5 NSLog(@"0:%@",[dateFormatter stringFromDate:[NSDate date]]); 6 7 8 9 [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]]; 10 11 NSLog(@"1:%@",[dateFormatter stringFromDate:[NSDate date]]); 12 13 14 15 [dateFormatter setTimeZone:[NSTimeZone defaultTimeZone]]; 16 17 NSLog(@"2:%@",[dateFormatter stringFromDate:[NSDate date]]); 18 19 20 21 [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; 22 23 NSLog(@"3:%@",[dateFormatter stringFromDate:[NSDate date]]); 24 25 26 27 [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Shanghai"]]; 28 29 NSLog(@"4:%@",[dateFormatter stringFromDate:[NSDate date]]); 30 31 32 33 [dateFormatter setTimeZone:[[NSTimeZone alloc] initWithName:@"Asia/Shanghai"]]; 34 35 NSLog(@"5:%@",[dateFormatter dateFromString:[dateFormatter stringFromDate:[NSDate date]]]); 36 37
0:2015/02/03 09:41:14
1:2015/02/03 09:41:14
2:2015/02/03 09:41:14
3:2015/02/03 09:41:14
4:2015/02/03 09:41:14
5:2015-02-03 01:41:14 +0000
附带NSDate详情链接:http://www.cnblogs.com/ios-wmm/archive/2013/04/21/3034204.html
时间: 2024-10-17 20:54:07