I had assumed it would be as simple as $ENV{TZ}
, but the TZ
environment variable is not set, and yet the date
command still knows I am in EDT, so there must be some other way of determining timezone (other than saying chomp(my $tz = qx/date +%Z/);
).
views:
95answers:
3I thought about %Z, but I remember something about it not working on some systems.
Chas. Owens
2009-06-13 03:24:30
According to man strftime, %Z is a standard specification and should be supported on all platforms.
Igor Krivokon
2009-06-13 03:35:15
I think I was remembering this from the POSIX docs: The "Z" specifier is notoriously unportable since the names of timezones are non‐standard. Sticking to the numeric specifiers is the safest route. But I think this is probably safe enough for my purposes.
Chas. Owens
2009-06-13 04:20:30
+4
A:
use POSIX;
localtime();
my ($std, $dst) = POSIX::tzname();
tzname()
gives you access to the POSIX global tzname
- but you need to have called localtime()
for it to be set in the first place.
Beano
2009-06-13 07:05:59
+3
A:
If you want something more portable than POSIX
(but probably much slower) you can use DateTime::TimeZone for this:
use DateTime::TimeZone;
print DateTime::TimeZone->new( name => 'local' )->name();
Dave Rolsky
2009-06-13 11:58:07