Dates and formatters
Dates and formatters
- Subject: Dates and formatters
- From: James Spencer <email@hidden>
- Date: Mon, 1 Nov 2004 21:12:35 -0600
There is something about NSCalendarDates and formatters that I'm not
getting. I have a table, one column of which displays a date
associated with the row. The column has a date formatter attached to
it with a simple format string "%m/%d/%y" which of course refers to a
date string of the form "10/7/04". Typically, the user creates this
date in a detail window in which the user types a date and time local
to the user. However, what the table is supposed to display is that
same date and time converted to a date local to a remote location in
another time zone.
I use the information from the detail window to create an
NSCalendarDate and offset it to the correct time zone for the remote
with -setTimeZone: (it matters whether the event being recorded
occurred before or after midnight in the remote time zone). This works
just fine. Assuming the user is in the Central Time Zone (GMT - 6
hours) and the user types in 10/7/04 and 10:00 p.m., if the remote
location is say Spain (GMT + 1 hour) then an NSCalendarDate is created
whose -description shows: 2004-10-08 05:00:00 +0100 which is exactly
what I want. Then when my table calls - (id)tableView:(NSTableView
*)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(int)row, this NSCalendarDate is being returned to the column.
Here's the problem: what I would like displayed in the table is the
date in the remote time zone so using my example, I would like the
table to display "10/8/04" but what is being displayed is in the users
local time zone, i.e. 10/7/04. I take it that the NSDateFormatter
formats date objects in the time zone of the user without looking at
the time zone in the NSCalendarDate object. Is there anyway to correct
this short of writing a custom date formatter?
Thanks,
Spence
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
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