NSString转NSDate为nil原因

2016-06-02  本文已影响109人  Loki_

以下方法得到的createDate为nil

NSDateFormatter*formatter = [[NSDateFormatteralloc]init];

//格式Thu May 05 10:04:37

+0800 2016

[formattersetDateFormat:@"EEE MMM dd

HH:mm:ss zzz yyyy"];

NSDate*createDate =

[formatterdateFromString:@"Thu May 05 10:04:37 +0800

2016"];

正确方式:

NSDateFormatter*formatter = [[NSDateFormatteralloc]init];

//格式Thu May 05 10:04:37

+0800 2016

[formattersetDateFormat:@"EEE MMM dd

HH:mm:ss zzz yyyy"];

formatter.locale= [[NSLocalealloc]initWithLocaleIdentifier:@"en_US"];

NSDate*createDate =

[formatterdateFromString:@"Thu May 05 10:04:37 +0800

2016"];

上一篇下一篇

猜你喜欢

热点阅读