RE: Getting the GMT time
RE: Getting the GMT time
- Subject: RE: Getting the GMT time
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Fri, 16 Apr 2004 17:04:30 -0400
>
The following snippet I've tried but I get a nil result:
>
>
NSTimeZone *t = [[NSTimeZone alloc] init];
>
>
if ([t initWithName:@"GMT"] == nil) {
>
NSLog(@"***** NULL Time zone???");
>
}
>
Never call init... unless you are also calling alloc. Bad things can happen
if you do.
Probably what you want is
NSTimeZone *t = [NSTimeZone timeZoneForSecondsFromGMT:0];
which gives you an autoreleased object.
>
NSCalendarDate *GMTtime = [NSCalendarDate calendarDate];
>
[GMTtime setTimeZone:t];
The docs are not clear on what happens if you change the time zone of an
NSCalendarDate. It probably continues to represent the same moment in time,
and just converts it so that it is represented in terms of the new time
zone, but I'm not sure. You also might consider:
NSTimeZone *t = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSCalendarDate *GMTtime = [[NSDate date] dateWithCalendarFormat:@"%H:%M:%S"
timeZone:t];
Read the docs for NSTimeZone, NSDate and NSCalendarDate as well as the Dates
and Times programming topic.
Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.