0

I'm having issues setting a NSDate when the Date Format in the phone is set to 12h(am, pm) instead of 24h.

Here's the code.

[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *dateStart = [df dateFromString:@"2013-10-11 18:00:00"]];
NSLog(@"Date: %@", dateStart);

This code either prints "2013-10-11 18:00:00" when the device's time is set to 24h, like NSDateFormatter or null if the settings of the phone is set to 12hrs. You can change the settings by going to Settings->General->Date and Time-> there you set the checkbox to a 12 hour time format.

Why is this even happening? Why is the phone settings affecting the app's behaviour?

Thanks.

subharb
  • 3,374
  • 8
  • 41
  • 72
  • 1
    It's a "feechure" (which is a term of the art meaning a bug that's been documented to look like "we meant to do that"). – Hot Licks Oct 11 '13 at 16:02
  • Yes, it was that same bug. But that post I think is harder to find specially if you don't know that this is a bug from Apple... – subharb Oct 11 '13 at 16:53
  • Yeah, it's a lot harder to blame you for missing that one in a search than, say, the ever-popular "my date is off by a day" timezone snafu. – Hot Licks Oct 11 '13 at 19:07

1 Answers1

-1

I've faced similar problem and i've 'solved' it working with 24h. If the clock is set to 12h the App change the time to 24 h (not in settings) but internally to save in core data.

RFG
  • 2,880
  • 3
  • 28
  • 44