开发者

NSDateFormatter not working... where am i wrong?

开发者 https://www.devze.com 2023-02-28 22:05 出处:网络
i\'m trying to parse a date writte in UTC format. For example NSString *o = @\"2011-04-23$20:28:00Z\";

i'm trying to parse a date writte in UTC format. For example

NSString *o = @"2011-04-23$20:28:00Z";

Here's the code i'm using:

df = [[NSDateFormatte开发者_开发知识库r alloc] init];        
[df setDateFormat:@"yyyy-MM-dd$HH:mm:00Z"];

 NSLog(@"^%@^ => %@", o, [df stringFromDate:[df dateFromString:o]]);

it produces the logging

^2011-04-23$20:28:00Z^ => (null)

Where am i wrong?

Thanks!


The Z symbol in a date format string specifies a field for the timezone, if you want to parse the literal "Z", you will need to escape it with a ': yyyy-MM-dd$HH:mm:00'Z.

0

精彩评论

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