1Date::Format(3) User Contributed Perl Documentation Date::Format(3)
2
3
4
6 Date::Format - Date formating subroutines
7
9 use Date::Format;
10
11 @lt = localtime(time);
12
13 print time2str($template, time);
14 print strftime($template, @lt);
15
16 print time2str($template, time, $zone);
17 print strftime($template, @lt, $zone);
18
19 print ctime(time);
20 print asctime(@lt);
21
22 print ctime(time, $zone);
23 print asctime(@lt, $zone);
24
26 This module provides routines to format dates into ASCII strings. They
27 correspond to the C library routines "strftime" and "ctime".
28
29 time2str(TEMPLATE, TIME [, ZONE])
30 "time2str" converts "TIME" into an ASCII string using the
31 conversion specification given in "TEMPLATE". "ZONE" if given
32 specifies the zone which the output is required to be in, "ZONE"
33 defaults to your current zone.
34
35 strftime(TEMPLATE, TIME [, ZONE])
36 "strftime" is similar to "time2str" with the exception that the
37 time is passed as an array, such as the array returned by
38 "localtime".
39
40 ctime(TIME [, ZONE])
41 "ctime" calls "time2str" with the given arguments using the
42 conversion specification "%a %b %e %T %Y\n"
43
44 asctime(TIME [, ZONE])
45 "asctime" calls "time2str" with the given arguments using the
46 conversion specification "%a %b %e %T %Y\n"
47
49 Date::Format is capable of formating into several languages by creating
50 a language specific object and calling methods, see Date::Language
51
52 my $lang = Date::Language->new('German');
53 $lang->time2str("%a %b %e %T %Y\n", time);
54
55 I am open to suggestions on this.
56
58 Each conversion specification is replaced by appropriate characters
59 as described in the following list. The appropriate characters
60 are determined by the LC_TIME category of the program's locale.
61
62 %% PERCENT
63 %a day of the week abbr
64 %A day of the week
65 %b month abbr
66 %B month
67 %c MM/DD/YY HH:MM:SS
68 %C ctime format: Sat Nov 19 21:05:57 1994
69 %d numeric day of the month, with leading zeros (eg 01..31)
70 %e like %d, but a leading zero is replaced by a space (eg 1..32)
71 %D MM/DD/YY
72 %G GPS week number (weeks since January 6, 1980)
73 %h month abbr
74 %H hour, 24 hour clock, leading 0's)
75 %I hour, 12 hour clock, leading 0's)
76 %j day of the year
77 %k hour
78 %l hour, 12 hour clock
79 %L month number, starting with 1
80 %m month number, starting with 01
81 %M minute, leading 0's
82 %n NEWLINE
83 %o ornate day of month -- "1st", "2nd", "25th", etc.
84 %p AM or PM
85 %P am or pm (Yes %p and %P are backwards :)
86 %q Quarter number, starting with 1
87 %r time format: 09:05:57 PM
88 %R time format: 21:05
89 %s seconds since the Epoch, UCT
90 %S seconds, leading 0's
91 %t TAB
92 %T time format: 21:05:57
93 %U week number, Sunday as first day of week
94 %w day of the week, numerically, Sunday == 0
95 %W week number, Monday as first day of week
96 %x date format: 11/19/94
97 %X time format: 21:05:57
98 %y year (2 digits)
99 %Y year (4 digits)
100 %Z timezone in ascii. eg: PST
101 %z timezone in format -/+0000
102
103 %d, %e, %H, %I, %j, %k, %l, %m, %M, %q, %y and %Y can be output in
104 Roman numerals by prefixing the letter with "O", e.g. %OY will output
105 the year as roman numerals.
106
108 The functions in this module are limited to the time range that can be
109 represented by the time_t data type, i.e. 1901-12-13 20:45:53 GMT to
110 2038-01-19 03:14:07 GMT.
111
113 Graham Barr <gbarr@pobox.com>
114
116 Copyright (c) 1995-2009 Graham Barr. This program is free software; you
117 can redistribute it and/or modify it under the same terms as Perl
118 itself.
119
120
121
122perl v5.28.1 2009-12-12 Date::Format(3)