Hello eniad,
It seems that fellow Monks have already addressed your problem, but I want to add something minor here also. Since there is a minor bug on the module would you consider also of using another module? For example I put together a very simple example on my favorite module Date::Manip
regarding date manipulations.
The date formats that this modules can accept are many, just briefly see Date::Manip::Examples. The modules can convert in one step the human readable format date to epoch and vice versa.
I also included a minor comment in case you want to play with different time zone(s).
Sample of code bellow:
#!/usr/bin/perl
use strict;
use warnings;
use Date::Manip;
use feature 'say';
my @dates = ( "1899-06-24 09:44:00",
"1900-12-31 23:59:59",
"1901-01-01 00:00:00",
"1960-12-31 23:59:59",
"1966-06-24 09:44:00",
"1968-12-31 23:59:59",
"1969-01-01 00:00:00",
"1969-12-31 23:59:59",
"1970-01-01 00:00:01",
"2000-01-01 00:00:00",
"2017-06-24 23:59:59",
"2018-06-24 09:44:00",
"2238-06-24 09:44:00" );
foreach my $datestr (@dates) {
my $epochSecs = UnixDate($datestr,'%s');
my $date = UnixDate( ParseDateString("epoch $epochSecs"), "%Y-%m-%
+d %T");
say "Date value = ".$datestr.", epoch = ".$epochSecs.", date = "
+.$date;
}
=timezone
my $timezone = UnixDate( Date_ConvTZ( "today", 'CET', 'PST' ), "%Y-%m-
+%d %T");
say $timezone;
=cut
__END__
$ perl test.pl
Date value = 1899-06-24 09:44:00, epoch = -2225459760, date = 1899-06
+-24 09:44:00
Date value = 1900-12-31 23:59:59, epoch = -2177456401, date = 1900-12
+-31 23:59:59
Date value = 1901-01-01 00:00:00, epoch = -2177456400, date = 1901-01
+-01 00:00:00
Date value = 1960-12-31 23:59:59, epoch = -284000401, date = 1960-12-
+31 23:59:59
Date value = 1966-06-24 09:44:00, epoch = -111165360, date = 1966-06-
+24 09:44:00
Date value = 1968-12-31 23:59:59, epoch = -31539601, date = 1968-12-3
+1 23:59:59
Date value = 1969-01-01 00:00:00, epoch = -31539600, date = 1969-01-0
+1 00:00:00
Date value = 1969-12-31 23:59:59, epoch = -3601, date = 1969-12-31 23
+:59:59
Date value = 1970-01-01 00:00:01, epoch = -3599, date = 1970-01-01 00
+:00:01
Date value = 2000-01-01 00:00:00, epoch = 946681200, date = 2000-01-0
+1 00:00:00
Date value = 2017-06-24 23:59:59, epoch = 1498341599, date = 2017-06-
+24 23:59:59
Date value = 2018-06-24 09:44:00, epoch = 1529826240, date = 2018-06-
+24 09:44:00
Date value = 2238-06-24 09:44:00, epoch = 8472325440, date = 2238-06-
+24 09:44:00
Hope this helps, BR.
Seeking for Perl wisdom...on the process of learning...not there...yet!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.