Time::localtime(3pm)
๐ธ NAME ๐ธ
Okay bestie, meet Time::localtime(3pm) โ from the Perl Programmers Reference Guide โ itโs the by-name interface to Perlโs built-in localtime() function. Thatโs the whole vibe: you get the time fields by name instead of by mysterious list positions. ๐
โจ SYNOPSIS โจ
Like, literally the smallest taste:
use Time::localtime;
printf "Year is %d\n", localtime->year() + 1900;
$now = ctime();
use Time::localtime;
use File::stat;
$date_string = ctime(stat($file)->mtime);
๐ DESCRIPTION ๐
So hereโs the tea: this moduleโs default exports override the core localtime() function, replacing it with a version that returns "Time::tm" objects. Those objects have methods that return the similarly named structure field name from the Cโs tm structure from time.h โ namely sec, min, hour, mday, mon, year, wday, yday, and isdst. Periodt. ๐
You may also import all the structure fields directly into your namespace as regular variables using the :FIELDS import tag. (Note that this still overrides your core functions.) Access these fields as variables named with a preceding "tm_" in front their method names. Thus, "$tm_obj->mday()" corresponds to $tm_mday if you import the fields. Slay. ๐ฆ
The ctime() function provides a way of getting at the scalar sense of the original CORE::localtime() function.
To access this functionality without the core overrides, pass the "use" an empty import list, and then access function functions with their full qualified names. On the other hand, the built-ins are still available via the "CORE::" pseudo-package. ๐
๐ซถ NOTE ๐ซถ
While this class is currently implemented using the Class::Struct module to build a struct-like class, you shouldnโt rely upon this. No cap โ thatโs an implementation detail, not a promise. ๐
๐ AUTHOR ๐
Tom Christiansen. Iconic. ๐
Signed, sealed, delivered: this page is from perl v5.42.3, dated 2026-11-03, and itโs the Time::localtime(3pm) manual page. Bye bestie! ๐
๐ฆ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms