1Time::localtime(3pm) Perl Programmers Reference Guide Time::localtime(3pm)
2
3
4
6 Time::localtime - by-name interface to Perl's built-in localtime()
7 function
8
10 use Time::localtime;
11 printf "Year is %d\n", localtime->year() + 1900;
12
13 $now = ctime();
14
15 use Time::localtime;
16 use File::stat;
17 $date_string = ctime(stat($file)->mtime);
18
20 This module's default exports override the core localtime() function,
21 replacing it with a version that returns "Time::tm" objects. This
22 object has methods that return the similarly named structure field name
23 from the C's tm structure from time.h; namely sec, min, hour, mday,
24 mon, year, wday, yday, and isdst.
25
26 You may also import all the structure fields directly into your
27 namespace as regular variables using the :FIELDS import tag. (Note
28 that this still overrides your core functions.) Access these fields as
29 variables named with a preceding "tm_" in front their method names.
30 Thus, "$tm_obj->mday()" corresponds to $tm_mday if you import the
31 fields.
32
33 The ctime() function provides a way of getting at the scalar sense of
34 the original CORE::localtime() function.
35
36 To access this functionality without the core overrides, pass the "use"
37 an empty import list, and then access function functions with their
38 full qualified names. On the other hand, the built-ins are still
39 available via the "CORE::" pseudo-package.
40
42 While this class is currently implemented using the Class::Struct
43 module to build a struct-like class, you shouldn't rely upon this.
44
46 Tom Christiansen
47
48
49
50perl v5.34.1 2022-03-15 Time::localtime(3pm)