DateTime says
This module does not parse dates! That means there is no constructor to which you can pass things like "March 3, 1970 12:34".
Instead, take a look at the various DateTime::Format::* modules on CPAN. These parse all sorts of different date formats, and you're bound to find something that can handle your particular needs.
I searched around in metacpan and found Date::Parse and the Synopsis seems to do the job well, at least for epoch
use strict; use warnings; use Data::Dump qw/pp dd/; use Date::Parse; use DateTime; pp my $date = 'Sat Jun 4 22:47:31 2022'; pp my $time = str2time($date); pp my ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date); my $dt = DateTime->from_epoch ( epoch => $time, time_zone => 'UTC', # fill in your timezone ); print $dt;
"Sat Jun 4 22:47:31 2022" 1654375651 (31, 47, 22, 4, 5, 122, undef) 2022-06-04T20:47:31
Other modules - especially the one suggested by 1nickt - might be better, I just wanted to demonstrate how to solve it by yourself.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: change hour in timestamp
by LanX
in thread change hour in timestamp
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |