• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Date parsing problem (when running on iphone only)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date parsing problem (when running on iphone only)


  • Subject: Re: Date parsing problem (when running on iphone only)
  • From: Jacob Rhoden <email@hidden>
  • Date: Thu, 05 Mar 2009 07:42:45 +1100

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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >Date parsing problem (when running on iphone only) (From: Jacob Rhoden <email@hidden>)
 >Re: Date parsing problem (when running on iphone only) (From: Jacob Rhoden <email@hidden>)
 >Re: Date parsing problem (when running on iphone only) (From: Christopher Kane <email@hidden>)

  • Prev by Date: Re: NSTextField woes
  • Next by Date: Re: Saving a plist file from a thumbdrive
  • Previous by thread: Re: Date parsing problem (when running on iphone only)
  • Next by thread: Re: Date parsing problem (when running on iphone only)
  • Index(es):
    • Date
    • Thread