NSString NSDate when time is in 24-hour format

I have a format string on January 25, 2011 3:17. I need to convert it to NSDate. I used NSDateFormatter with the format @ "MMM d, yyyy h: mm a". It works well if the iphone time is 12 hours, but returns zero if the time is 24 hours. Can anyone help me with this ??

+4
source share
2 answers

Capital H is used for the 24-hour format. Doesn't 24-hour time usually exclude part of AM / PM? If so, your format string should be: @"MMM d yyyy H:mm" .

Here is a link to Unicode date format strings.

+7
source

This is a bug in NSDateFormatter. You can get around this by manually setting the locale in the date format:

 [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"] autorelease]]; 
+2
source

Source: https://habr.com/ru/post/1337255/


All Articles