Date and Time

use v5.36;
my $now = time;                                      # epoch seconds
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($now);
printf "%04d-%02d-%02d\n", $year + 1900, $mon + 1, $mday;   # year is offset from 1900, month is 0-based!
say scalar localtime;                                # "Fri Oct 24 10:30:00 2025"
say scalar gmtime;

use POSIX qw(strftime);
say strftime('%Y-%m-%d %H:%M:%S', localtime);

use Time::Local qw(timelocal_posix timegm_posix);    # date parts → epoch
my $epoch = timegm_posix(0, 0, 12, 24, 9, 125);     # Oct 24 2025 12:00 UTC (posix: year-1900, month 0-based)

use Time::HiRes qw(time sleep usleep);               # high-resolution timing
my $t0 = time; sleep 0.25; printf "%.3f s\n", time - $t0;

use Time::Piece;                                     # core, OO
my $t = localtime;
say $t->ymd, ' ', $t->hms, ' ', $t->day_of_week, ' ', $t->strftime('%A');
my $parsed = Time::Piece->strptime('2025-10-24', '%Y-%m-%d');
my $diff = $t - $parsed;                             # Time::Seconds object
say int($diff->days), ' days';
use Time::Seconds; my $next_week = $t + ONE_WEEK;

use DateTime;                                        # CPA
…