Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / May 2006



Tip: Looking for answers? Try searching our database.

any sample code out there that shows NSTimeZone?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Santa Claus - 29 May 2006 22:40 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.
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/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.