> This is not a DateTime object.
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 Data::Dump qw/pp dd/;
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
"Sat Jun 4 22:47:31 2022"
(31, 47, 22, 4, 5, 122, undef)
Other modules - especially the one suggested by 1nickt - might be better, I just wanted to demonstrate how to solve it by yourself.
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>
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
Want more info? How to link
or How to display code and escape characters
are good places to start.