Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: How to format dates prior to 1970?

by 1nickt (Abbot)
on Jul 10, 2017 at 13:52 UTC ( #1194702=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to format dates prior to 1970?
in thread How to format dates prior to 1970?

Well, since the exception is apparently caused by Time::Piece (even though it's a core module), try using something else:

use strict; use warnings; use feature 'say'; use DateTime::Format::Strptime; my $parser = DateTime::Format::Strptime->new(pattern => '%m/%d/%Y', on +_error => 'croak'); my $date = '05/10/1969'; my $dt = $parser->parse_datetime( $date ); say $dt->ymd;
What does that do on your Windows system?


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^4: How to format dates prior to 1970?
by Hanfresco (Novice) on Jul 10, 2017 at 16:11 UTC
    #!/usr/bin/perl use v5.10; use strict; use warnings; use Data::Dumper; use DateTime::Format::Strptime; $Data::Dumper::Sortkeys = 1; my $parser = DateTime::Format::Strptime->new(pattern => '%m/%d/%Y', on +_error => 'croak'); my $date = '05/10/1969'; my $dt = $parser->parse_datetime($date); say $dt->ymd; say $dt->strftime('%Y-%m-%d');
    Interesting! This seems to work even with strftime; no seg faults!

      DateTime isn't based around epoch times, so it will indeed work with older-than-epoch times without problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1194702]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2020-11-30 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?