rokadave has asked for the wisdom of the Perl Monks concerning the following question:
I figured could hack it out by measuring the difference returned by localtime and gmtime, but shuddered when I thought of what that would actually be doing. Converting epoch time to local time, by referencing the local timezone rules, converting epoch time to UTC by referencing the local timezone rules, all to infer.... the local timezone rules.
I poked around a bit and discovered Time::Piece. I was satisfied when it provided a method called tzoffset which gave me my offset in seconds. Curious, I peeked into the code to find they were doing the same ugly gmtime-localtime trick, and were even proud enough of that method to include a comment of attribution. Time::Local seems to use the same trick.
Is there no better way? Is the gmtime-localtime trick the slow-but-preferred way for portability and reliability?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What's my timezone offset?
by BigLug (Chaplain) on Feb 10, 2006 at 03:23 UTC |