i'm writing a routine that determines sunrise and sunset in an online game
but i need to know the user's local time zone to offset the calculations by
yes, u saw "systemtimezone" but no sample code that shows how everything's supposed to work.
David Phillip Oster - 30 May 2006 04:56 GMT
> i'm writing a routine that determines sunrise and sunset in an online game
> but i need to know the user's local time zone to offset the calculations by
> yes, u saw "systemtimezone" but no sample code that shows how everything's
> supposed to work.
[NSCalendarDate calendarDate] returns the time of now.
[[[NSCalendarDate calendarDate] timeZone] secondsFromGMT] gives you
seconds away from GMT.
Tom Harrington - 30 May 2006 05:03 GMT
> i'm writing a routine that determines sunrise and sunset in an online game
> but i need to know the user's local time zone to offset the calculations by
> yes, u saw "systemtimezone" but no sample code that shows how everything's
> supposed to work.
NSTimezone is staggeringly simple to use. You get the local timezone as
an NSTimezone like this:
NSTimezone *tz = [NSTimeZone localTimeZone];
You can then ask tz for information about the zone:
// In Colorado this returns "America/Denver"
NSString *zoneName = [tz name];
// In Colorado this returns "MDT"
NSString *zoneAbberv = [tz abbreviation];
Other details are available, like the offset from UTC-- just look at the
NSTimezone documentation.

Signature
Tom "Tom" Harrington
Macaroni, Automated System Maintenance for Mac OS X.
Version 2.0: Delocalize, Repair Permissions, lots more.
See http://www.atomicbird.com/