• 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: Christopher Kane <email@hidden>
  • Date: Wed, 4 Mar 2009 07:42:55 -0800

On Mar 4, 2009, at 4:22 AM, Jacob Rhoden wrote:

On 4/3/09 10:15 PM, Jacob Rhoden wrote:
Anyone experience this weird behaviour with date parsing? Given the following code, it produces a different log output when running in the simulator or on the iPhone!!!

   NSString* test = @"Monday 26 January 2009 3:47:33 pm +0000";
   NSDateFormatter *df = [[NSDateFormatter alloc] init];
   [df setDateFormat: @"EEEE dd MMMM yyyy h:mm:ss a Z"];
   NSLog(@"DATE: %@ to %i", test, [df dateFromString: test]);

This is the NSLog output on the iphone:
2009-03-04 22:08:49.645 Test[2875:20b] DATE: Monday 26 January 2009 3:47:33 pm +0000 to 0


And this on the simulator:
2009-03-04 22:09:05.095 Test[68041:20b] DATE: Monday 26 January 2009 3:47:33 pm +0000 to 5432224
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.

[This applies to Mac OS X as well as iPhone OS, it's just that iPhone OS tends to exercise such override settings more -- currently.]


Chris Kane Cocoa Frameworks, Apple

_______________________________________________

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


  • Follow-Ups:
    • Re: Date parsing problem (when running on iphone only)
      • From: Jacob Rhoden <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>)

  • Prev by Date: Re: Odd crash
  • Next by Date: Re: Odd crash
  • 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