开发者

NSDateFormatter problem

I am trying to get NSDate from string but its returning nil. I tried this开发者_运维技巧:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-mm-dd'T'HH:mm:ss'Z'"];
NSDate *date = [dateFormatter dateFromString:@"2010-05-07T10:12:32UTC"];
NSLog(@"Success date=%@",[date description]);

Thanks


Your date format string expects the date to end with a literal Z. But your date ends with the string UTC. There are several ways to fix this.

  1. Change your date format string to @"yyyy-mm-dd'T'HH:mm:ss'UTC'".
  2. Or, change your date string to @"2010-05-07T10:12:32Z".

Or, you could change your date format string to: @"yyyy-mm-dd'T'HH:mm:ssz". This will recognize some common 3-letter time zone names, such as PDT for Pacific Daylight Time. Unfortunately, however, it will not recognize UTC as a time zone name (you’d have to use “GMT”).


The literal 'Z' won't match the string UTC.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜