嗨我有一个像这样的字符串:Thu, 09 Jun 2011 5:00 pm CST
,其中CST可以是任何时区或其他东西。
帮助我已经尝试过了,但它是空的:
NSDateFormatter *formatter2 = [[NSDateFormatter alloc]init];
[formatter2 setDateFormat:@"EEE, dd MMM yyyy h:mm 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 :(得分:3)
您不是在考虑AM / PM。我相信那是'a'
。
尝试:
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