ios 时间格式互相转换

1 view
Skip to first unread message

澂~の~霴

unread,
Dec 12, 2011, 11:02:26 PM12/12/11
to iOS development
NSString * ldate=@"2011-12-13 11:07:10";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // 格式要与ldate的一
样,否则得到的是null值。

NSData *date=[dateFormat dateFromString:ldate];

[dateFormat setDateFormat:@"yyyyMMdd"]; // 再改为你想要的时间格式
NSString *date2=[dateFormat stringFromDate:date];

Reply all
Reply to author
Forward
0 new messages