Re: NSDateFormatter time zone not "sticking"? [SOLVED]
Re: NSDateFormatter time zone not "sticking"? [SOLVED]
- Subject: Re: NSDateFormatter time zone not "sticking"? [SOLVED]
- From: Doug Knowles <email@hidden>
- Date: Wed, 21 Sep 2005 08:28:20 -0400
OK; putting this into the thread because I get most of my answers from
these archives... ;=)
The time zone support is documented as a 10.4 feature, and the doc
does point out that the 10.4 "behaviors" are only available if you
create and initialize the formatter with alloc and init.
Having already created and bound a date formatter in IB, I
optimistically believed that invoking ...
[ibTideTableDateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4]
...would make the 10.4 features work.
Apparently not.
I'm now allocating and initializing a formatter in my window
controller's windowDidLoad method, and setting the table column's data
cell's formatter directly in the code.
The doc does say you have to do that, but the existence of
setFormatterBehavior is a bit puzzling to me, since it doesn't seem to
do what it says.
Doug K;
On 9/20/05, Doug Knowles <email@hidden> wrote:
> Hi, all,
>
> I'm trying to display a table with a date column which renders dates
> in a specific time zone (not the current time zone of the system).
>
> My table column is bound to an NSDate value, and the NSTableColumn has
> an NSDateFormatter configured appropriately. I've created an outlet
> in my window controller that is connected to the NSDateFormatter, so I
> have programmatic access to the formatter.
>
> When I reload the data for the table, I invoke setTimeZone: on the
> date formatter with the appropriate time zone; however, the dates are
> always displayed in the current time zone of my system. The absolute
> times are correct; they're just not adjusting for the time zone (i.e.,
> it shows sunrise in England as 1:55AM US/Eastern).
>
> When I try some logging for debugging, it appears that NSDateFormatter
> is ignoring my setTimeZone calls:
>
> // update the time zone of the date formatter
> NSTimeZone *tz = [NSTimeZone timeZoneWithName:[currentStation timeZoneStr]];
> NSLog( @"...setting time zone to %@", tz );
> [ibTideTableDateFormatter setTimeZone:tz];
> NSLog( @"...reading back time zone as %@", [ibTideTableDateFormatter
> timeZone] );
>
> ...yields:
>
> 2005-09-20 16:30:26.965 OSXTide[22333] ...setting time zone to
> Europe/London (BST) offset 3600 (Daylight)
> 2005-09-20 16:30:26.965 OSXTide[22333] ...reading back time zone as
> Local Time Zone [US/Eastern (EDT) offset -14400 (Daylight)]
>
> Explicitly retaining the NSTimeZone object (which didn't seem like it
> should be necessary) didn't affect the results.
>
> I see NSCalendarDate supports a time zone specification; should I be
> using it in place of NSDate?
>
> Thanks in advance...
>
> Doug K;
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden