On 5/3/09 2:42 AM, Christopher Kane wrote:
It seems that if you have your Regional settings to Chinese the date is not parsed. What is the proper way to parse an "English" formatted date?
Yes, the date formatter you're creating defaults to using the user's locale, which can have settings which override even your attempt to set a specific format string. Do this after creating the formatter: [df setLocale:[NSLocale systemLocale]]; to set a generic locale object on the formatter.
Thanks very much, that was the hint I needed to get it working. To share in case someone else has this problem for future reference: If you are trying to parse a date that will always be English, ie from a web page or web service, you need to tell the date parser to use the language of that web service.

ie:
    NSString* test = @"Monday 26 January 2009 3:47:33 pm +0000";
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setLocale: [[[NSLocale alloc] initWithLocaleIdentifier:@"en_UK"] autorelease]];
    [df setDateFormat: @"EEEE dd MMMM yyyy h:mm:ss a Z"];

If you don't do this, when you run your code on say a Chinese computer, it will fail (I am assuming its because January and Monday are not valid Chinese words).

Imagine tracking down a bug that your software works on most computers except that one person in the office or that one iphone user who has changed their Regional Settings (It threw me because I am used to Java's date parsing being language agnostic)

Best regards,
Jacob

--
____________________________________________
Jacob Rhoden          http://jacobrhoden.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to