The core Time::Piece module seems to handle most of your dates but anything earlier than the start of the 20th century can't be parsed and causes an error.
use strict; use warnings; use feature qw{ say }; use Time::Piece; my @dates = ( q{1960-12-31 23:59:59}, q{1966-06-24 09:44:00}, q{1968-12-31 23:59:59}, q{1969-01-01 00:00:00}, q{1969-12-31 23:59:59}, q{1970-01-01 00:00:01}, q{2000-01-01 00:00:00}, q{2017-06-24 23:59:59}, q{2018-06-24 09:44:00}, q{2238-06-24 09:44:00}, q{1900-12-31 23:59:59}, q{1901-01-01 00:00:00}, q{1900-01-01 00:00:00}, q{1899-12-31 23:59:59}, ); foreach my $date ( @dates ) { my $tp = Time::Piece->strptime( $date, q{%Y-%m-%d %T} ); say $date, q{ -> epoch }, $tp->epoch(); }
The output.
1960-12-31 23:59:59 -> epoch -283996801 1966-06-24 09:44:00 -> epoch -111161760 1968-12-31 23:59:59 -> epoch -31536001 1969-01-01 00:00:00 -> epoch -31536000 1969-12-31 23:59:59 -> epoch -1 1970-01-01 00:00:01 -> epoch 1 2000-01-01 00:00:00 -> epoch 946684800 2017-06-24 23:59:59 -> epoch 1498348799 2018-06-24 09:44:00 -> epoch 1529833440 2238-06-24 09:44:00 -> epoch 8472332640 1900-12-31 23:59:59 -> epoch -2177452801 1901-01-01 00:00:00 -> epoch -2177452800 1900-01-01 00:00:00 -> epoch -2208988800 Error parsing time at /usr/lib/x86_64-linux-gnu/perl/5.22/Time/Piece.p +m line 469.
I hope this is of interest.
Cheers,
JohnGG
In reply to Re: Date::Parse - how to correctly parse dates between 1901 and 1969
by johngg
in thread Date::Parse - how to correctly parse dates between 1901 and 1969
by eniad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |