I have the server where system timezone is EST
It was set with
# timedatectl set-timezone EST
# timedatectl
Local time: Tue 2019-06-18 03:29:42 EST
Universal time: Tue 2019-06-18 08:29:42 UTC
RTC time: Tue 2019-06-18 08:29:42
Time zone: EST (EST, -0500)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
Then in my perl code i try to detect timezone and convert time to UTC And for some reason, a timezone is detected as EDT. Currently (summer) EST is one our after EDT
My perl code is
# cat test.cgi # code file is named test.cgi
#!/usr/bin/perl -w
use Date::Manip;
print "Local time: ".UnixDate("now","%Y-%m-%d %H:%M:%S %Z")."\n";
# get local system timezone
my $TZ = UnixDate("now","%Z");
# convert time to GMT
my $dtlocal = Date_ConvTZ(ParseDate(UnixDate("now","%g")),$TZ,"GMT");
# format GMT time
my $dt = UnixDate($dtlocal,"%Y-%m-%d %H:%M:%S");
print "Timezone: $TZ\n";
print "UTC time: $dt\n";
And i execute the script
# date
Tue Jun 18 04:17:56 EST 2019
# date -u
Tue Jun 18 09:17:58 UTC 2019
# ./test.cgi
Local time: 2019-06-18 04:18:00 EDT
Timezone: EDT
UTC time: 2019-06-18 08:18:00
What can be the reason that Date::Manip detects timezone wrongly? Is there other good way to detect system timezone?
UPDATE.
I have just found that POSIX detects timezone correctly. So, the problem is with Date::Manip
use POSIX;
print strftime("%Z", localtime()), "\n";