2011-06-09 96 views
2

嗨我有一個字符串是這樣的: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 

我這樣做有些事情錯了嗎?幫我,我是新來的。

回答

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 
+0

您的岩石。只是說。謝謝老人! – BigBoy 2011-06-09 16:09:31