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