码迷,mamicode.com
首页 > 移动开发 > 详细

IOS - NSDate 自己挖的坑,自己跳

时间:2015-02-03 10:51:27      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

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

IOS - NSDate 自己挖的坑,自己跳

标签:

原文地址:http://www.cnblogs.com/tx8899/p/4269227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!