1Template::Plugin::Date(U3s)er Contributed Perl DocumentatTieomnplate::Plugin::Date(3)
2
3
4
6 Template::Plugin::Date - Plugin to generate formatted date strings
7
9 [% USE date %]
10
11 # use current time and default format
12 [% date.format %]
13
14 # specify time as seconds since epoch
15 # or as a 'h:m:s d-m-y' or 'y-m-d h:m:s' string
16 [% date.format(960973980) %]
17 [% date.format('4:20:36 21/12/2000') %]
18 [% date.format('2000/12/21 4:20:36') %]
19
20 # specify format
21 [% date.format(mytime, '%H:%M:%S') %]
22
23 # specify locale
24 [% date.format(date.now, '%a %d %b %y', 'en_GB') %]
25
26 # named parameters
27 [% date.format(mytime, format = '%H:%M:%S') %]
28 [% date.format(locale = 'en_GB') %]
29 [% date.format(time = date.now,
30 format = '%H:%M:%S',
31 locale = 'en_GB'
32 use_offset = 1) %]
33
34 # specify default format to plugin
35 [% USE date(format = '%H:%M:%S', locale = 'de_DE') %]
36
37 [% date.format %]
38 ...
39
41 The "Date" plugin provides an easy way to generate formatted time and
42 date strings by delegating to the "POSIX" "strftime()" routine.
43
44 The plugin can be loaded via the familiar USE directive.
45
46 [% USE date %]
47
48 This creates a plugin object with the default name of '"date"'. An
49 alternate name can be specified as such:
50
51 [% USE myname = date %]
52
53 The plugin provides the "format()" method which accepts a time value, a
54 format string and a locale name. All of these parameters are optional
55 with the current system time, default format ('"%H:%M:%S %d-%b-%Y"')
56 and current locale being used respectively, if undefined. Default
57 values for the time, format and/or locale may be specified as named
58 parameters in the "USE" directive.
59
60 [% USE date(format = '%a %d-%b-%Y', locale = 'fr_FR') %]
61
62 When called without any parameters, the "format()" method returns a
63 string representing the current system time, formatted by "strftime()"
64 according to the default format and for the default locale (which may
65 not be the current one, if locale is set in the "USE" directive).
66
67 [% date.format %]
68
69 The plugin allows a time/date to be specified as seconds since the
70 epoch, as is returned by "time()".
71
72 File last modified: [% date.format(filemod_time) %]
73
74 The time/date can also be specified as a string of the form "h:m:s
75 d/m/y" or "y/m/d h:m:s". Any of the characters : / - or space may be
76 used to delimit fields.
77
78 [% USE day = date(format => '%A', locale => 'en_GB') %]
79 [% day.format('4:20:00 9-13-2000') %]
80
81 Output:
82
83 Tuesday
84
85 A format string can also be passed to the "format()" method, and a
86 locale specification may follow that.
87
88 [% date.format(filemod, '%d-%b-%Y') %]
89 [% date.format(filemod, '%d-%b-%Y', 'en_GB') %]
90
91 A fourth parameter allows you to force output in GMT, in the case of
92 seconds-since-the-epoch input:
93
94 [% date.format(filemod, '%d-%b-%Y', 'en_GB', 1) %]
95
96 Note that in this case, if the local time is not GMT, then also
97 specifying '%Z' (time zone) in the format parameter will lead to an
98 extremely misleading result.
99
100 To maintain backwards compatibility, using the %z placeholder in the
101 format string (to output the UTC offset) currently requires the
102 "use_offset" parameter to be set to a true value. This can also be
103 passed as the fifth parameter to format (but the former will probably
104 be clearer).
105
106 Any or all of these parameters may be named. Positional parameters
107 should always be in the order "($time, $format, $locale)".
108
109 [% date.format(format => '%H:%M:%S') %]
110 [% date.format(time => filemod, format => '%H:%M:%S') %]
111 [% date.format(mytime, format => '%H:%M:%S') %]
112 [% date.format(mytime, format => '%H:%M:%S', locale => 'fr_FR') %]
113 [% date.format(mytime, format => '%H:%M:%S', gmt => 1) %]
114 ...etc...
115
116 The "now()" method returns the current system time in seconds since the
117 epoch.
118
119 [% date.format(date.now, '%A') %]
120
121 The "calc()" method can be used to create an interface to the
122 "Date::Calc" module (if installed on your system).
123
124 [% calc = date.calc %]
125 [% calc.Monday_of_Week(22, 2001).join('/') %]
126
127 The "manip()" method can be used to create an interface to the
128 "Date::Manip" module (if installed on your system).
129
130 [% manip = date.manip %]
131 [% manip.UnixDate("Noon Yesterday","%Y %b %d %H:%M") %]
132
134 Thierry-Michel Barral wrote the original plugin.
135
136 Andy Wardley provided some minor fixups/enhancements, a test script and
137 documentation.
138
139 Mark D. Mills cloned "Date::Manip" from the "Date::Calc" sub-plugin.
140
142 Copyright (C) 2000-2007 Thierry-Michel Barral, Andy Wardley.
143
144 This module is free software; you can redistribute it and/or modify it
145 under the same terms as Perl itself.
146
148 Template::Plugin, POSIX
149
150
151
152perl v5.32.0 2020-07-28 Template::Plugin::Date(3)