• 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: NSDateFormatter bug in timeZone
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDateFormatter bug in timeZone


  • Subject: Re: NSDateFormatter bug in timeZone
  • From: jon <email@hidden>
  • Date: Mon, 27 Apr 2009 07:54:52 -0600

I was not using the term Data Source properly most likely, this is what i was doing..

	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	[defaults setObject:theDate forKey:@"the date"];

in a different Class object at a later time,  i retrieve it like this.

	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	NSDate *theDate = [defaults objectForKey:@"the date"];

that is what i meant by storing the data...

(shouldn't PDT mean just one thing? shouldn't it be that simple? I'll try your suggestion, thanks, i'll try it with zzz, and with zzzzzzz)

(I'm not sure how to properly reply to the list yet, should i reply to both You and the list? as i'm doing here)
thanks,
Jon.


On Apr 27, 2009, at 3:27 AM, Alastair Houghton wrote:


it appears there is a bug in Apple's date formatter:

NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:@"MMM-dd-yy HH:mm:ss zzz"];
NSDate *theDate = [inputFormatter dateFromString:@"Apr-04-09 10:30:03 PDT"];


this gives the wrong timezone in "theDate"??? (unless of course you happen to be in the PDT timezone) it looks like it ignores the format, and just puts in current time zone.

I'm not sure that things are quite as simple as you think :-)

The problem with the three-letter time zone codes is that many of them are ambiguous. For instance, you might think EST meant UTC-5, whereas an Australian would expect EST to be UTC+10. As a result, you probably need to specify a bit more information rather than just "PDT"; I'm not 100% certain, but the following *might* work:

NSDate *theDate = [inputFormatter dateFromString:@"Apr-04-09 10:30:03 PST8PDT"];

also using the natural language formater properly gives me the correct time Zone, but as soon as you store it in a Data Source, it comes back out with the current time zone, and the time adjusted so that it is correct time at least... but this shouldn't happen? should it.

You can't store something in a data source, at least not for the usual Cocoa meaning of data source. Data sources are a type of delegate object, usually one that you implement yourself (unless you're using bindings, in which case the system does it for you).


Where are you storing the date? And in what form? Are you using bindings or Core Data, or did you implement your own data source object?

_______________________________________________

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: NSDateFormatter bug in timeZone
      • From: Alastair Houghton <email@hidden>
References: 
 >NSDateFormatter bug in timeZone (From: Jon <email@hidden>)
 >Re: NSDateFormatter bug in timeZone (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: figuring out which TableView I am?
  • Next by Date: Re: NSDateFormatter bug in timeZone
  • Previous by thread: Re: NSDateFormatter bug in timeZone
  • Next by thread: Re: NSDateFormatter bug in timeZone
  • Index(es):
    • Date
    • Thread