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)
-
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.
|