in reply to Re: Morning or Night?
in thread Morning or Night?

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.