To expand on blakem's solution, the % 24 is needed to make sure you stay within the confines of a 24 hour clock ... otherwise you end up with a non-existant 25th hour (which is > 12, hence PM :)).
Unfortunately, setting $ENV{TZ} doesn't appear to be all that portable (works under FreeBSD and prolly the other Unices, but not Windows), otherwise you could simplify all of that code and logic to ...
use POSIX 'strftime';
my $timezone = 'CST6CDT'; # EST5EDT MST7MDT PST8PDT
my $date = do {
local $ENV{TZ} = $timezone;
strftime( '%y %m %A %I %M %S %p', localtime );
};
my($year,$month,$day,$hour,$mins,$secs,$ampm) = split( ' ', $date );
--k.
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.