Recently I wrote a program that needed to know the system’s timezone offset from GMT.
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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.