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 conver‐
31 sion specification given in "TEMPLATE". "ZONE" if given specifies
32 the zone which the output is required to be in, "ZONE" defaults to
33 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 "local‐
38 time".
39
40 ctime(TIME [, ZONE])
41 "ctime" calls "time2str" with the given arguments using the conver‐
42 sion specification "%a %b %e %T %Y\n"
43
44 asctime(TIME [, ZONE])
45 "asctime" calls "time2str" with the given arguments using the con‐
46 version specification "%a %b %e %T %Y\n"
47
49 Date::Format is capable of formating into several languages, these are
50 English, French, German and Italian. Changing the language is done via
51 a static method call, for example
52
53 Date::Format->language('German');
54
55 will change the language in which all subsequent dates are formatted.
56
57 This is only a first pass, I am considering changing this to be
58
59 $lang = Date::Language->new('German');
60 $lang->time2str("%a %b %e %T %Y\n", time);
61
62 I am open to suggestions on this.
63
65 Each conversion specification is replaced by appropriate characters
66 as described in the following list. The appropriate characters
67 are determined by the LC_TIME category of the program's locale.
68
69 %% PERCENT
70 %a day of the week abbr
71 %A day of the week
72 %b month abbr
73 %B month
74 %c MM/DD/YY HH:MM:SS
75 %C ctime format: Sat Nov 19 21:05:57 1994
76 %d numeric day of the month, with leading zeros (eg 01..31)
77 %e numeric day of the month, without leading zeros (eg 1..31)
78 %D MM/DD/YY
79 %G GPS week number (weeks since January 6, 1980)
80 %h month abbr
81 %H hour, 24 hour clock, leading 0's)
82 %I hour, 12 hour clock, leading 0's)
83 %j day of the year
84 %k hour
85 %l hour, 12 hour clock
86 %L month number, starting with 1
87 %m month number, starting with 01
88 %M minute, leading 0's
89 %n NEWLINE
90 %o ornate day of month -- "1st", "2nd", "25th", etc.
91 %p AM or PM
92 %P am or pm (Yes %p and %P are backwards :)
93 %q Quarter number, starting with 1
94 %r time format: 09:05:57 PM
95 %R time format: 21:05
96 %s seconds since the Epoch, UCT
97 %S seconds, leading 0's
98 %t TAB
99 %T time format: 21:05:57
100 %U week number, Sunday as first day of week
101 %w day of the week, numerically, Sunday == 0
102 %W week number, Monday as first day of week
103 %x date format: 11/19/94
104 %X time format: 21:05:57
105 %y year (2 digits)
106 %Y year (4 digits)
107 %Z timezone in ascii. eg: PST
108 %z timezone in format -/+0000
109
110 %d, %e, %H, %I, %j, %k, %l, %m, %M, %q, %y and %Y can be output in
111 Roman numerals by prefixing the letter with "O", e.g. %OY will output
112 the year as roman numerals.
113
115 Graham Barr <gbarr@pobox.com>
116
118 Copyright (c) 1995-1999 Graham Barr. All rights reserved. This program
119 is free software; you can redistribute it and/or modify it under the
120 same terms as Perl itself.
121
122
123
124perl v5.8.8 2003-06-02 Date::Format(3)