开发者

How to format this date

Hi I have a string that is like this: Thu, 09 Jun 2011 5:00 pm CST, where CST could be any time zone or something.

Help I tried this already but it's null:

NSDateFormatter *formatter2 = [[NSDateFormatter alloc]init];
[formatter2 setDateFormat:@"EEE, dd MMM yyyy h:mm z"];
[formatter2 setLocale:[开发者_C百科[[NSLocale alloc]initWithLocaleIdentifier:@"en_US_POSIX"]autorelease]];
[formatter2 setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
NSDate *time = [formatter2 dateFromString:@"Thu, 09 Jun 2011 5:00 pm KST"];
[formatter2 release];
NSLog(@"%@",time); //null

Am I doing somethings wrong? Help me I'm new.


You aren't accounting for the AM/PM. I believe that that is 'a'.

try:

NSDateFormatter *formatter2 = [[NSDateFormatter alloc]init];
[formatter2 setDateFormat:@"EEE, dd MMM yyyy h:mm a z"];
[formatter2 setLocale:[[[NSLocale alloc]initWithLocaleIdentifier:@"en_US_POSIX"]autorelease]];
[formatter2 setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
NSDate *time = [formatter2 dateFromString:@"Thu, 09 Jun 2011 5:00 pm KST"];
[formatter2 release];
NSLog(@"%@",time); //null
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜