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
Other answers
Thanks fixed it up with: [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]];
user170385
Related Q & A:
- How to edit a custom region from an Omega subtheme in Drupal 7?Best solution by Drupal Answers
- What is Black Sea Region?Best solution by Yahoo! Answers
- How to change HD phillips televsion picture format to a diffrent format when many are non selectable. please?Best solution by Yahoo! Answers
- What do I need to transfer a tape format into a digital format?Best solution by wikihow.com
- Is the DS Region Free?Best solution by ds.about.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.