Re: NSDateFormatter bug in timeZone
Re: NSDateFormatter bug in timeZone
- Subject: Re: NSDateFormatter bug in timeZone
- From: Alastair Houghton <email@hidden>
- Date: Mon, 27 Apr 2009 10:27:04 +0100
On 27 Apr 2009, at 02:41, Jon 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?
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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