Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: change hour in timestamp

by LanX (Saint)
on Jun 04, 2022 at 21:55 UTC ( [id://11144398]=note: print w/replies, xml ) Need Help??


in reply to change hour in timestamp

> This is not a DateTime object.

DateTime says

    Parsing Dates

    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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found