1DATE(1P) POSIX Programmer's Manual DATE(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 date - write the date and time
13
15 date [-u] [+format]
16
17
18
19 date [-u] mmddhhmm[[cc]yy]
20
21
23 The date utility shall write the date and time to standard output or
24 attempt to set the system date and time. By default, the current date
25 and time shall be written. If an operand beginning with '+' is speci‐
26 fied, the output format of date shall be controlled by the conversion
27 specifications and other text in the operand.
28
30 The date utility shall conform to the Base Definitions volume of
31 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
32
33 The following option shall be supported:
34
35 -u Perform operations as if the TZ environment variable was set to
36 the string "UTC0", or its equivalent historical value of "GMT0"
37 . Otherwise, date shall use the timezone indicated by the TZ
38 environment variable or the system default if that variable is
39 unset or null.
40
41
43 The following operands shall be supported:
44
45 +format
46 When the format is specified, each conversion specifier shall be
47 replaced in the standard output by its corresponding value. All
48 other characters shall be copied to the output without change.
49 The output shall always be terminated with a <newline>.
50
51
52 Conversion Specifications
53 %a Locale's abbreviated weekday name.
54
55 %A Locale's full weekday name.
56
57 %b Locale's abbreviated month name.
58
59 %B Locale's full month name.
60
61 %c Locale's appropriate date and time representation.
62
63 %C Century (a year divided by 100 and truncated to an integer) as a
64 decimal number [00,99].
65
66 %d Day of the month as a decimal number [01,31].
67
68 %D Date in the format mm/dd/yy.
69
70 %e Day of the month as a decimal number [1,31] in a two-digit field
71 with leading space character fill.
72
73 %h A synonym for %b .
74
75 %H Hour (24-hour clock) as a decimal number [00,23].
76
77 %I Hour (12-hour clock) as a decimal number [01,12].
78
79 %j Day of the year as a decimal number [001,366].
80
81 %m Month as a decimal number [01,12].
82
83 %M Minute as a decimal number [00,59].
84
85 %n A <newline>.
86
87 %p Locale's equivalent of either AM or PM.
88
89 %r 12-hour clock time [01,12] using the AM/PM notation; in the
90 POSIX locale, this shall be equivalent to %I : %M : %S %p .
91
92 %S Seconds as a decimal number [00,60].
93
94 %t A <tab>.
95
96 %T 24-hour clock time [00,23] in the format HH:MM:SS.
97
98 %u Weekday as a decimal number [1,7] (1=Monday).
99
100 %U Week of the year (Sunday as the first day of the week) as a dec‐
101 imal number [00,53]. All days in a new year preceding the first
102 Sunday shall be considered to be in week 0.
103
104 %V Week of the year (Monday as the first day of the week) as a dec‐
105 imal number [01,53]. If the week containing January 1 has four
106 or more days in the new year, then it shall be considered week
107 1; otherwise, it shall be the last week of the previous year,
108 and the next week shall be week 1.
109
110 %w Weekday as a decimal number [0,6] (0=Sunday).
111
112 %W Week of the year (Monday as the first day of the week) as a dec‐
113 imal number [00,53]. All days in a new year preceding the first
114 Monday shall be considered to be in week 0.
115
116 %x Locale's appropriate date representation.
117
118 %X Locale's appropriate time representation.
119
120 %y Year within century [00,99].
121
122 %Y Year with century as a decimal number.
123
124 %Z Timezone name, or no characters if no timezone is determinable.
125
126 %% A percent sign character.
127
128
129 See the Base Definitions volume of IEEE Std 1003.1-2001, Section 7.3.5,
130 LC_TIME for the conversion specifier values in the POSIX locale.
131
132 Modified Conversion Specifications
133 Some conversion specifiers can be modified by the E and O modifier
134 characters to indicate a different format or specification as specified
135 in the LC_TIME locale description (see the Base Definitions volume of
136 IEEE Std 1003.1-2001, Section 7.3.5, LC_TIME). If the corresponding
137 keyword (see era, era_year, era_d_fmt, and alt_digits in the Base Defi‐
138 nitions volume of IEEE Std 1003.1-2001, Section 7.3.5, LC_TIME) is not
139 specified or not supported for the current locale, the unmodified con‐
140 version specifier value shall be used.
141
142 %Ec Locale's alternative appropriate date and time representation.
143
144 %EC The name of the base year (period) in the locale's alternative
145 representation.
146
147 %Ex Locale's alternative date representation.
148
149 %EX Locale's alternative time representation.
150
151 %Ey Offset from %EC (year only) in the locale's alternative repre‐
152 sentation.
153
154 %EY Full alternative year representation.
155
156 %Od Day of month using the locale's alternative numeric symbols.
157
158 %Oe Day of month using the locale's alternative numeric symbols.
159
160 %OH Hour (24-hour clock) using the locale's alternative numeric sym‐
161 bols.
162
163 %OI Hour (12-hour clock) using the locale's alternative numeric sym‐
164 bols.
165
166 %Om Month using the locale's alternative numeric symbols.
167
168 %OM Minutes using the locale's alternative numeric symbols.
169
170 %OS Seconds using the locale's alternative numeric symbols.
171
172 %Ou Weekday as a number in the locale's alternative representation
173 (Monday = 1).
174
175 %OU Week number of the year (Sunday as the first day of the week)
176 using the locale's alternative numeric symbols.
177
178 %OV Week number of the year (Monday as the first day of the week,
179 rules corresponding to %V ), using the locale's alternative
180 numeric symbols.
181
182 %Ow Weekday as a number in the locale's alternative representation
183 (Sunday = 0).
184
185 %OW Week number of the year (Monday as the first day of the week)
186 using the locale's alternative numeric symbols.
187
188 %Oy Year (offset from %C ) in alternative representation.
189
190
191
192 mmddhhmm[[cc]yy]
193
194 Attempt to set the system date and time from the value given in
195 the operand. This is only possible if the user has appropriate
196 privileges and the system permits the setting of the system date
197 and time. The first mm is the month (number); dd is the day
198 (number); hh is the hour (number, 24-hour system); the second mm
199 is the minute (number); cc is the century and is the first two
200 digits of the year (this is optional); yy is the last two digits
201 of the year and is optional. If century is not specified, then
202 values in the range [69,99] shall refer to years 1969 to 1999
203 inclusive, and values in the range [00,68] shall refer to years
204 2000 to 2068 inclusive. The current year is the default if yy is
205 omitted.
206
207 Note:
208 It is expected that in a future version of IEEE Std 1003.1-2001
209 the default century inferred from a 2-digit year will change.
210 (This would apply to all commands accepting a 2-digit year as
211 input.)
212
213
214
216 Not used.
217
219 None.
220
222 The following environment variables shall affect the execution of date:
223
224 LANG Provide a default value for the internationalization variables
225 that are unset or null. (See the Base Definitions volume of
226 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
227 ables for the precedence of internationalization variables used
228 to determine the values of locale categories.)
229
230 LC_ALL If set to a non-empty string value, override the values of all
231 the other internationalization variables.
232
233 LC_CTYPE
234 Determine the locale for the interpretation of sequences of
235 bytes of text data as characters (for example, single-byte as
236 opposed to multi-byte characters in arguments).
237
238 LC_MESSAGES
239 Determine the locale that should be used to affect the format
240 and contents of diagnostic messages written to standard error.
241
242 LC_TIME
243 Determine the format and contents of date and time strings writ‐
244 ten by date.
245
246 NLSPATH
247 Determine the location of message catalogs for the processing of
248 LC_MESSAGES .
249
250 TZ Determine the timezone in which the time and date are written,
251 unless the -u option is specified. If the TZ variable is unset
252 or null and -u is not specified, an unspecified system default
253 timezone is used.
254
255
257 Default.
258
260 When no formatting operand is specified, the output in the POSIX locale
261 shall be equivalent to specifying:
262
263
264 date "+%a %b %e %H:%M:%S %Z %Y"
265
267 The standard error shall be used only for diagnostic messages.
268
270 None.
271
273 None.
274
276 The following exit values shall be returned:
277
278 0 The date was written successfully.
279
280 >0 An error occurred.
281
282
284 Default.
285
286 The following sections are informative.
287
289 Conversion specifiers are of unspecified format when not in the POSIX
290 locale. Some of them can contain <newline>s in some locales, so it may
291 be difficult to use the format shown in standard output for parsing the
292 output of date in those locales.
293
294 The range of values for %S extends from 0 to 60 seconds to accommodate
295 the occasional leap second.
296
297 Although certain of the conversion specifiers in the POSIX locale (such
298 as the name of the month) are shown with initial capital letters, this
299 need not be the case in other locales. Programs using these fields may
300 need to adjust the capitalization if the output is going to be used at
301 the beginning of a sentence.
302
303 The date string formatting capabilities are intended for use in Grego‐
304 rian-style calendars, possibly with a different starting year (or
305 years). The %x and %c conversion specifications, however, are intended
306 for local representation; these may be based on a different, non-Grego‐
307 rian calendar.
308
309 The %C conversion specification was introduced to allow a fallback for
310 the %EC (alternative year format base year); it can be viewed as the
311 base of the current subdivision in the Gregorian calendar. The century
312 number is calculated as the year divided by 100 and truncated to an
313 integer; it should not be confused with the use of ordinal numbers for
314 centuries (for example, "twenty-first century".) Both the %Ey and %y
315 can then be viewed as the offset from %EC and %C, respectively.
316
317 The E and O modifiers modify the traditional conversion specifiers, so
318 that they can always be used, even if the implementation (or the cur‐
319 rent locale) does not support the modifier.
320
321 The E modifier supports alternative date formats, such as the Japanese
322 Emperor's Era, as long as these are based on the Gregorian calendar
323 system. Extending the E modifiers to other date elements may provide an
324 implementation-defined extension capable of supporting other calendar
325 systems, especially in combination with the O modifier.
326
327 The O modifier supports time and date formats using the locale's alter‐
328 native numerical symbols, such as Kanji or Hindi digits or ordinal num‐
329 ber representation.
330
331 Non-European locales, whether they use Latin digits in computational
332 items or not, often have local forms of the digits for use in date for‐
333 mats. This is not totally unknown even in Europe; a variant of dates
334 uses Roman numerals for the months: the third day of September 1991
335 would be written as 3.IX.1991. In Japan, Kanji digits are regularly
336 used for dates; in Arabic-speaking countries, Hindi digits are used.
337 The %d, %e, %H, %I, %m, %S, %U, %w, %W, and %y conversion specifica‐
338 tions always return the date and time field in Latin digits (that is, 0
339 to 9). The %O modifier was introduced to support the use for display
340 purposes of non-Latin digits. In the LC_TIME category in localedef, the
341 optional alt_digits keyword is intended for this purpose. As an exam‐
342 ple, assume the following (partial) localedef source:
343
344
345 alt_digits "";"I";"II";"III";"IV";"V";"VI";"VII";"VIII" \
346 "IX";"X";"XI";"XII"
347 d_fmt "%e.%Om.%Y"
348
349 With the above date, the command:
350
351
352 date "+%x"
353
354 would yield 3.IX.1991. With the same d_fmt, but without the alt_digits,
355 the command would yield 3.9.1991.
356
358 1. The following are input/output examples of date used at arbitrary
359 times in the POSIX locale:
360
361
362 $ date
363 Tue Jun 26 09:58:10 PDT 1990
364
365
366 $ date "+DATE: %m/%d/%y%nTIME: %H:%M:%S"
367 DATE: 11/02/91
368 TIME: 13:36:16
369
370
371 $ date "+TIME: %r"
372 TIME: 01:36:32 PM
373
374 2. Examples for Denmark, where the default date and time format is %a
375 %d %b %Y %T %Z :
376
377
378 $ LANG=da_DK.iso_8859-1 date
379 ons 02 okt 1991 15:03:32 CET
380
381
382 $ LANG=da_DK.iso_8859-1 \
383 date "+DATO: %A den %e. %B %Y%nKLOKKEN: %H:%M:%S"
384 DATO: onsdag den 2. oktober 1991
385 KLOKKEN: 15:03:56
386
387 3. Examples for Germany, where the default date and time format is %a
388 %d . %h . %Y, %T %Z :
389
390
391 $ LANG=De_DE.88591 date
392 Mi 02.Okt.1991, 15:01:21 MEZ
393
394
395 $ LANG=De_DE.88591 date "+DATUM: %A, %d. %B %Y%nZEIT: %H:%M:%S"
396 DATUM: Mittwoch, 02. Oktober 1991
397 ZEIT: 15:02:02
398
399 4. Examples for France, where the default date and time format is %a
400 %d %h %Y %Z %T :
401
402
403 $ LANG=Fr_FR.88591 date
404 Mer 02 oct 1991 MET 15:03:32
405
406
407 $ LANG=Fr_FR.88591 date "+JOUR: %A %d %B %Y%nHEURE: %H:%M:%S"
408 JOUR: Mercredi 02 octobre 1991
409 HEURE: 15:03:56
410
412 Some of the new options for formatting are from the ISO C standard.
413 The -u option was introduced to allow portable access to Coordinated
414 Universal Time (UTC). The string "GMT0" is allowed as an equivalent TZ
415 value to be compatible with all of the systems using the BSD implemen‐
416 tation, where this option originated.
417
418 The %e format conversion specification (adopted from System V) was
419 added because the ISO C standard conversion specifications did not pro‐
420 vide any way to produce the historical default date output during the
421 first nine days of any month.
422
423 There are two varieties of day and week numbering supported (in addi‐
424 tion to any others created with the locale-dependent %E and %O modifier
425 characters):
426
427 * The historical variety in which Sunday is the first day of the week
428 and the weekdays preceding the first Sunday of the year are consid‐
429 ered week 0. These are represented by %w and %U . A variant of this
430 is %W, using Monday as the first day of the week, but still refer‐
431 ring to week 0. This view of the calendar was retained because so
432 many historical applications depend on it and the ISO C standard
433 strftime() function, on which many date implementations are based,
434 was defined in this way.
435
436 * The international standard, based on the ISO 8601:2000 standard
437 where Monday is the first weekday and the algorithm for the first
438 week number is more complex: If the week (Monday to Sunday) contain‐
439 ing January 1 has four or more days in the new year, then it is week
440 1; otherwise, it is week 53 of the previous year, and the next week
441 is week 1. These are represented by the new conversion specifica‐
442 tions %u and %V, added as a result of international comments.
443
445 None.
446
448 The System Interfaces volume of IEEE Std 1003.1-2001, printf(), strf‐
449 time()
450
452 Portions of this text are reprinted and reproduced in electronic form
453 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
454 -- Portable Operating System Interface (POSIX), The Open Group Base
455 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
456 Electrical and Electronics Engineers, Inc and The Open Group. In the
457 event of any discrepancy between this version and the original IEEE and
458 The Open Group Standard, the original IEEE and The Open Group Standard
459 is the referee document. The original Standard can be obtained online
460 at http://www.opengroup.org/unix/online.html .
461
462
463
464IEEE/The Open Group 2003 DATE(1P)