2

Posted app for store verified working on iOS 6.1.3 (iPhone4/4S/iPad3 Retina) but tried it on an iPhone5 with iOS 6.1.4 installed and ran into problems with date formatting.

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd.MM.yyyy HH:mm:ss"];

    // key eventFromDate return string 04.08.2013 11:00:00

    NSDate *date = [formatter dateFromString:[self valueForKey:@"eventFromDate"]];
    [formatter setDateFormat:@"dd.MM"];
    NSString *str = [formatter stringFromDate:date];
    [formatter release];

Problem is date becomes null running 6.1.4 but running 6.1.3 returns dd.MM as expected.

Anyone experiencing the same or is this just a weird issue on my side?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 3
    Have you looked at the date string you get from `[self valueForKey:@"eventFromDate"]` and verified it is in the expected format in the case where the resulting `NSDate` is `nil`? – rmaddy Jul 30 '13 at 21:41
  • 1
    rmaddy is likely correct - I just tested this with `@"04.08.2013 11:00:00"` on my iPhone 5 and it returns 04.08 as you would expect. – jsd Jul 30 '13 at 21:42
  • 1
    Are the 2 devices set to the same locale? – Wain Jul 30 '13 at 21:44
  • I have checked that the eventFromDate is returning the expected format (the comment is copy paste from NSLog) and the iphone4/4s/5 has the same settings (restarted them both/removed app/reinstalled). Still it runs on 4.1.3 but not on 4.1.4. Might not have anything to do with the case but that is the only difference I can find. – Bjarne Valsvik Jul 30 '13 at 21:58
  • 1
    Compare the 24-hour time setting on the iPhone 5 compared to the other devices. What Region Format is selected on iPhone 5 and the other devices? – rmaddy Jul 30 '13 at 22:03
  • `NSDate *date = [formatter dateFromString:[self valueForKey:@"eventFromDate"]];` -- This is the sort of thing you shouldn't do. Break into two statements with a temp in-between and testing/debug is a lot simpler. – Hot Licks Jul 30 '13 at 22:16
  • (And I'm betting that rmaddy is correct, and there is a problem with the 12/24 configuration. You should set the formatter's locale to "en_US_POSIX".) – Hot Licks Jul 30 '13 at 22:19
  • Thanks. The locale did the trick. – Bjarne Valsvik Jul 30 '13 at 22:28
  • Keep in mind that changing the locale on the device isn't the solution. People will run your app from all over the world with different locales. Your code needs to work regardless of locale. – rmaddy Jul 31 '13 at 00:00
  • See this thread: http://stackoverflow.com/questions/6613110/what-is-the-best-way-to-deal-with-the-nsdateformatter-locale-feature – Hot Licks Jul 31 '13 at 15:53

0 Answers0