DATE(1P) | POSIX Programmer's Manual | DATE(1P) |
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
date — write the date and time
date [-u] [+format]
date [-u] mmddhhmm[[cc]yy]
The date utility shall write the date and time to standard output or attempt to set the system date and time. By default, the current date and time shall be written. If an operand beginning with '+' is specified, the output format of date shall be controlled by the conversion specifications and other text in the operand.
The date utility shall conform to the Base Definitions volume of POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
The following option shall be supported:
The following operands shall be supported:
See the Base Definitions volume of POSIX.1‐2017, Section 7.3.5, LC_TIME for the conversion specifier values in the POSIX locale.
Some conversion specifiers can be modified by the E and O modifier characters to indicate a different format or specification as specified in the LC_TIME locale description (see the Base Definitions volume of POSIX.1‐2017, Section 7.3.5, LC_TIME). If the corresponding keyword (see era, era_year, era_d_fmt, and alt_digits in the Base Definitions volume of POSIX.1‐2017, Section 7.3.5, LC_TIME) is not specified or not supported for the current locale, the unmodified conversion specifier value shall be used.
Not used.
None.
The following environment variables shall affect the execution of date:
Default.
When no formatting operand is specified, the output in the POSIX locale shall be equivalent to specifying:
date "+%a %b %e %H:%M:%S %Z %Y"
The standard error shall be used only for diagnostic messages.
None.
None.
The following exit values shall be returned:
Default.
The following sections are informative.
Conversion specifiers are of unspecified format when not in the POSIX locale. Some of them can contain <newline> characters in some locales, so it may be difficult to use the format shown in standard output for parsing the output of date in those locales.
The range of values for %S extends from 0 to 60 seconds to accommodate the occasional leap second.
Although certain of the conversion specifiers in the POSIX locale (such as the name of the month) are shown with initial capital letters, this need not be the case in other locales. Programs using these fields may need to adjust the capitalization if the output is going to be used at the beginning of a sentence.
The date string formatting capabilities are intended for use in Gregorian-style calendars, possibly with a different starting year (or years). The %x and %c conversion specifications, however, are intended for local representation; these may be based on a different, non-Gregorian calendar.
The %C conversion specification was introduced to allow a fallback for the %EC (alternative year format base year); it can be viewed as the base of the current subdivision in the Gregorian calendar. The century number is calculated as the year divided by 100 and truncated to an integer; it should not be confused with the use of ordinal numbers for centuries (for example, ``twenty-first century''.) Both the %Ey and %y can then be viewed as the offset from %EC and %C, respectively.
The E and O modifiers modify the traditional conversion specifiers, so that they can always be used, even if the implementation (or the current locale) does not support the modifier.
The E modifier supports alternative date formats, such as the Japanese Emperor's Era, as long as these are based on the Gregorian calendar system. Extending the E modifiers to other date elements may provide an implementation-defined extension capable of supporting other calendar systems, especially in combination with the O modifier.
The O modifier supports time and date formats using the locale's alternative numerical symbols, such as Kanji or Hindi digits or ordinal number representation.
Non-European locales, whether they use Latin digits in computational items or not, often have local forms of the digits for use in date formats. This is not totally unknown even in Europe; a variant of dates uses Roman numerals for the months: the third day of September 1991 would be written as 3.IX.1991. In Japan, Kanji digits are regularly used for dates; in Arabic-speaking countries, Hindi digits are used. The %d, %e, %H, %I, %m, %S, %U, %w, %W, and %y conversion specifications always return the date and time field in Latin digits (that is, 0 to 9). The %O modifier was introduced to support the use for display purposes of non-Latin digits. In the LC_TIME category in localedef, the optional alt_digits keyword is intended for this purpose. As an example, assume the following (partial) localedef source:
alt_digits "";"I";"II";"III";"IV";"V";"VI";"VII";"VIII" \
"IX";"X";"XI";"XII" d_fmt "%e.%Om.%Y"
With the above date, the command:
date "+%x"
would yield 3.IX.1991. With the same d_fmt, but without the alt_digits, the command would yield 3.9.1991.
$ date Tue Jun 26 09:58:10 PDT 1990
$ date "+DATE: %m/%d/%y%nTIME: %H:%M:%S" DATE: 11/02/91 TIME: 13:36:16
$ date "+TIME: %r" TIME: 01:36:32 PM
$ LANG=da_DK.iso_8859-1 date ons 02 okt 1991 15:03:32 CET
$ LANG=da_DK.iso_8859-1 \
date "+DATO: %A den %e. %B %Y%nKLOKKEN: %H:%M:%S" DATO: onsdag den 2. oktober 1991 KLOKKEN: 15:03:56
$ LANG=De_DE.88591 date Mi 02.Okt.1991, 15:01:21 MEZ
$ LANG=De_DE.88591 date "+DATUM: %A, %d. %B %Y%nZEIT: %H:%M:%S" DATUM: Mittwoch, 02. Oktober 1991 ZEIT: 15:02:02
$ LANG=Fr_FR.88591 date Mer 02 oct 1991 MET 15:03:32
$ LANG=Fr_FR.88591 date "+JOUR: %A %d %B %Y%nHEURE: %H:%M:%S" JOUR: Mercredi 02 octobre 1991 HEURE: 15:03:56
Some of the new options for formatting are from the ISO C standard. The -u option was introduced to allow portable access to Coordinated Universal Time (UTC). The string "GMT0" is allowed as an equivalent TZ value to be compatible with all of the systems using the BSD implementation, where this option originated.
The %e format conversion specification (adopted from System V) was added because the ISO C standard conversion specifications did not provide any way to produce the historical default date output during the first nine days of any month.
There are two varieties of day and week numbering supported (in addition to any others created with the locale-dependent %E and %O modifier characters):
None.
The Base Definitions volume of POSIX.1‐2017, Section 7.3.5, LC_TIME, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
The System Interfaces volume of POSIX.1‐2017, fprintf(), strftime()
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
2017 | IEEE/The Open Group |