• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Getting the GMT time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Getting the GMT time (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: Best place to hide license files
  • Next by Date: Removing *other* app default?!?
  • Previous by thread: Re: Getting the GMT time
  • Next by thread: Launching plugins from command line
  • Index(es):
    • Date
    • Thread