I have the following code.
NSDateFormatter *df = ...;
[df setTimeZone:[NSTimeZone defaultTimeZone]];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"];
NSDate * date = [df dateFromString:date_string]; //here is the problem
In 24-hour mode everything is ok. When 12-hour mode is set on device, stringFromDate returns null. Format of date_string is the same all the time, date format too. Why does it happen?
12-hour mode to 24 hour mode:
For 24-hour mode to 12 hour mode just do the opposite
Try to set the locale in this way :
To force instead to 24 hour, you can use :
In your
NSDateFormatter "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"
HH
stands for 24 hour andhh
stands for 12 hour