Converting between time zones using setTimeZone
Converting between time zones using setTimeZone
- Subject: Converting between time zones using setTimeZone
- From: Sam Stigler <email@hidden>
- Date: Sat, 10 Feb 2007 14:53:55 -0800
Hi,
I'm trying to write an app that will convert between different time
zones, and I had been hoping that I could do that with a simple call
to [NSCalendarDate setTimeZone] or [NSDatePicker setTimeZone].
However, the first place I'm trying to use it is in converting the
current Pacific time to GMT for display in an NSDatePicker that's
running off of an NSTimer (updating every second), and for some
reason it's just not converting the time. Could you please take a
look at my code and let me know if I'm doing anything wrong?
In my awakeFromNib function for AppController:
// BEGIN CODE:
present_TZ = [NSTimeZone systemTimeZone];
gmt_TZ = [NSTimeZone timeZoneForSecondsFromGMT:0];
// GMT CLOCK:
clockTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(updateClock) userInfo:nil repeats:YES];
[clockTimer fire];
Here's the updateClock function:
-(void)updateClock
{
now = [NSCalendarDate calendarDate];
[gmtClock setDateValue:now];
[gmtClock setTimeZone:gmt_TZ];
[gmtDate setStringValue:[now descriptionWithCalendarFormat:@"%B %
d, %Y" timeZone:gmt_TZ locale:[[NSUserDefaults standardUserDefaults]
dictionaryRepresentation]]];
}
All of the necessary variables are declared in AppController.h.
Do you have any ideas as to why this could be happening? I have
tried using setTimeZone for both NSDatePicker and NSCalendarDate;
neither has worked. Am I correct in assuming that setTimeZone will
in fact do the time zone conversion?
Thanks,
Sam Stigler
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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