http://qs1969.pair.com?node_id=11144401


in reply to Re: change hour in timestamp
in thread change hour in timestamp

G'day JohnGG,

++ Upon reading the OP, I immediately thought of Time::Piece; then, after scrolling through the posts, I saw you'd used this already.

If I may, some minor improvements:

Here's the updated code:

my $date = q{Sat Jun 4 22:47:31 2022}; my $fmt_t = q{%a %b %d %T %Y}; my $fmt_s = q{%s %s %2d %s %d}; my $tp = Time::Piece->strptime($date, $fmt_t); $tp -= 2 * ONE_HOUR; say sprintf $fmt_s, split q{ }, $tp->strftime($fmt_t); $tp += 6 * ONE_DAY; say sprintf $fmt_s, split q{ }, $tp->strftime($fmt_t);

which outputs:

Sat Jun 4 20:47:31 2022 Fri Jun 10 20:47:31 2022

— Ken