Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Lost in DateTime !

by Discipulus (Canon)
on Jun 13, 2017 at 20:58 UTC ( [id://1192736]=note: print w/replies, xml ) Need Help??


in reply to Re: Lost in DateTime !
in thread Lost in DateTime !

..indeed i arrived to a similar conclusion, but slowly.. removing the +02 the conversion was made as expected: ie the +02 is the timezone hour modification

perl -MDateTime -e "@dtarg{qw(year month day hour minute second)}=spli +t/[\s:-]/,'2017-06-10 21:55:00';$dt=DateTime->new(%dtarg); print scal +ar localtime($dt->epoch)" Sat Jun 10 23:55:00 2017

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: Lost in DateTime !
by haukex (Archbishop) on Jun 13, 2017 at 21:10 UTC

    There is still a difference though, note that the DateTime object you've built is in the special "floating" time zone, and setting a time zone on it won't adjust the time value:

    use warnings; use strict; use DateTime::Format::Strptime; my $strp = DateTime::Format::Strptime->new( on_error=>'croak', pattern => '%Y-%m-%d %H:%M:%S%z'); my @dt = ( $strp->parse_datetime('2017-06-10 21:55:00+02'), DateTime->new(year=>2017,month=>6,day=>10, hour=>21,minute=>55,second=>0), $strp->parse_datetime('2017-06-10 21:55:00+00'), ); for my $i (0..$#dt) { print "$i: ",$dt[$i]->strftime('%Y-%m-%d %H:%M:%S %Z (%z)'),"\n"; $dt[$i]->set_time_zone('Europe/Paris'); print "$i: ",$dt[$i]->strftime('%Y-%m-%d %H:%M:%S %Z (%z)'),"\n"; } __END__ 0: 2017-06-10 21:55:00 +0200 (+0200) 0: 2017-06-10 21:55:00 CEST (+0200) 1: 2017-06-10 21:55:00 floating (+0000) 1: 2017-06-10 21:55:00 CEST (+0200) 2: 2017-06-10 21:55:00 UTC (+0000) 2: 2017-06-10 23:55:00 CEST (+0200)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-19 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found