how to get Region format?

NSDateFormatter with region format

  • I use this code to process a date string coming in from a json feed: NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle: NSDateFormatterLongStyle]; [formatter setFormatterBehavior: NSDateFormatterBehavior10_4]; [formatter setDateFormat: @"EEE, dd MMM yyyy HH:mm:ss +0000"]; so if I call NSDate *date = [formatter dateFromString: @"Tue, 08 Sep 2009 19:21:27 +0000"]; I get back a usable date if my region format is United States or United Kingdoms, but if I set it to Germany it returns nil. I understand there are some differences in behaviors across different locales, but if I define a format shouldn't that correct for any inconsistencies?

  • Answer:

    Names like "Tue" and "Sep" are English. Other languages use different names. If you want to be able to parse English dates independent of the device's region settings, set your DateFormatter's locale to en_US using the -setLocale: method.

user170385 at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

Thanks fixed it up with: [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]];

user170385

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.