document updated a month ago, on Dec 11, 2024
"Broken-down time" means the typical array ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst), and it correlates to the C standard library's struct tm.
Modules that are installed by default with Perl
- core functions
- gmtime — converts a Unix/epoch time into broken-down time (or, in scalar context, to a string)
- localtime — converts a Unix/epoch time into broken-down time (or, in scalar context, to a string)
- time — gets the current Unix/epoch time
- times — gets four current and cummulative times
- Time::Local — does the opposite of 'localtime' and 'gmtime' — converts an array of date-and-time-pieces (AKA a "broken-down time") back into a Unix/epoch time
- Time::Seconds — converts a seconds-based-interval into an equivalent interval of days, hours, months, etc. Probably often used in conjunction with Unix/epoch time-based times.
- Time::HiRes — high-resolution time routines
- Time::Piece — a core-module alternative to things like 'DateTime', 'Date::Manip', and 'Date::Simple'
- POSIX
Important modules that don't get installed by default
Parsing
- high-level
- medium-level
- low-level
If you're stuck using low-level parsing libraries, here is some useful information for writing custom date parsers.
Timezones
To change your script's local timezone at the top of the script:
use POSIX;
$ENV{TZ} = 'CST6CDT';
POSIX::tzset();
Formatting
- strftime() is the quintessential function here, and can be found in various places:
- rounding to English expressions (eg. "6 seconds ago", "4 days ago")