Search code examples
perldebian-bustercentos-6.9

How to set the same Date/Time for a Perl environment?


We have 2 environments: old (CentOS 6.9) and new (Debian 10).

Also we have this script:

#!/usr/bin/perl
use Time::ParseDate;
$seconds = parsedate('Jan 1, 1970');
print "$seconds\n";

It produces the following on old environment:

[user@old ~]$ ./test.pl
1577829600

And, It produces the following on new environment:

user@new:~$ ./test.pl
-10800

How do we fix this so that test.pl will output the same as on the old environment? Also please share some link(s) to read about this difference.


Solution

  • 1577829600 is the number of seconds between 2019-12-31T22:00:00Z and the unix epoch (1970-01-01T00:00:00Z).

    If you're trying to get the number of seconds since the unix epoch, you can use the builtin time.

    $ perl -e'CORE::say time'
    1580776856
    

    On the other hand, if you're trying to get the epoch time for Jan 1st of the current year of your local time zone, you can use parsedate('Jan 1').