NSDate from NSString when time is in 24 hr format
I have a string o开发者_如何学Gof the format Jan 25, 2011 3:17 AM. I need to convert it to NSDate. I used NSDateFormatter with format @"MMM d, yyyy h:mm a". It Works well if iphone time is in 12 hr format, but returns nil if time is in 24 hr format. Can any one help me with this????
Capital H is used for 24 hour format. Don't 24 hour times usually exclude the AM/PM part? If so, your format string should be: @"MMM d yyyy H:mm"
.
Here's a reference for Unicode date format strings.
It's a bug in NSDateFormatter. You can work around it by manually setting a locale on the date formatter:
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"] autorelease]];
精彩评论