试图通过以下代码将此2011-07-11 13:28:59 Etc/GMT
转换为NSDate,我得到nil
NSString *dateString=@"2011-07-11 13:28:59 Etc/GMT";
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"yyyy-MM-dd hh:mm:ss z"];
NSDate *purchaseDate = [dateformatter dateFromString:dateString];
这个日期来自苹果服务器本身,用于应用内购买验证。我已经讨论了很多关于时区的话题。但是没有一个显示如何转换这个Etc/GMT
i have tried z
zz
zzz
zzzz
Z
ZZ
ZZZ
ZZZZ
正确的dateFormat
是yyyy-MM-dd HH:mm:ss VV
,你应该用它来解决你的问题。
//Swift版本
let DateString = "2016-01-21 00:29:09 Etc/GMT"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"
var dateObject = dateFormatter.date(from: DateString)
NSString *dateString=@"2011-07-11 13:28:59 Etc/GMT";
dateString = [dateString stringByReplacingOccurrencesOfString:@"Etc/GMT" withString:@"GMT"];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];
// Or stuff....>>
NSDate *date = [dateformatter dateFromString: dateString];
NSLog(@"You may Need This =========%@",date);
dateformatter = [[[NSDateFormatter alloc] init] autorelease];
[dateformatter setDateFormat:@"yyyy-MM-dd hh:mm:ss a"];
NSString *convertedString = [dateformatter stringFromDate:date];
NSLog(@"Converted String : %@",convertedString);
///可能会有所帮助 =====>> http://unicode.org/reports/tr35/