DATE(1POSIX)

โœจ date(1POSIX) โœจ

okay bestie, this one's from the POSIX Programmer's Manual โ€” the manual page is literally called DATE(1POSIX) โ€” so buckle up, we're reading the spec-spec version ๐Ÿ’–


๐ŸŒธ PROLOG ๐ŸŒธ

Real talk first, no cap: this manual page is part of the <strong>POSIX Programmer's Manual</strong>. The <strong>Linux</strong> implementation of this interface may differ (so go peek at the corresponding Linux manual page if you need the tea on Linux behavior specifically), or honestly the interface may just not be implemented on Linux at all. It's giving "check your local listings" energy. ๐Ÿ’…


๐Ÿ‘‘ NAME ๐Ÿ‘‘

date โ€” write the date and time ๐Ÿ•โœจ


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

date [-u] [+format]

date [-u] mmddhhmm[[cc]yy]

two moods, one utility. read the time, or set the time. iconique.


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So the date utility shall write the date and time to <strong>standard output</strong>, or attempt to <strong>set the system date and time</strong>. Two paths, one bestie. ๐Ÿ’ซ

By default? The <strong>current date and time</strong> shall be written. Duh.

But here's the twist ๐ŸŒˆ โ€” if an operand beginning with + is specified, the output format of date shall be controlled by the <strong>conversion specifications</strong> and other text in that operand. You're basically doing arts and crafts with timestamps. Slay.


โœจ OPTIONS โœจ

First things first: date shall conform to the Base Definitions volume of POSIX.1โ€2017, Section 12.2, <strong>Utility Syntax Guidelines</strong>. Rules are rules, babe.

The following option shall be supported:

  • -u โ€” Perform operations as if the TZ environment variable was set to the string "UTC0", or its equivalent historical value of "GMT0". Otherwise, date shall use the timezone indicated by the TZ environment variable, or the system default if that variable is unset or null. (translation: UTC mode. no more timezone drama. ๐Ÿซถ)

๐Ÿ“ OPERANDS ๐Ÿ“

The following operands shall be supported:

  • +format โ€” When the format is specified, each conversion specifier shall be replaced in the standard output by its corresponding value. All other characters shall be copied to the output without change. The output shall always be terminated with a <newline>. (yes, always. the newline is non-negotiable ๐Ÿ’…)

๐ŸŒˆ Conversion Specifications ๐ŸŒˆ

okay this is the main character section. every one of these lil guys gets swapped for its value:

  • %a โ€” Locale's abbreviated weekday name.
  • %A โ€” Locale's full weekday name.
  • %b โ€” Locale's abbreviated month name.
  • %B โ€” Locale's full month name.
  • %c โ€” Locale's appropriate date and time representation.
  • %C โ€” Century (a year divided by 100 and truncated to an integer) as a decimal number [00,99].
  • %d โ€” Day of the month as a decimal number [01,31].
  • %D โ€” Date in the format mm/dd/yy.
  • %e โ€” Day of the month as a decimal number [1,31] in a two-digit field with leading <space> character fill.
  • %h โ€” A synonym for %b.
  • %H โ€” Hour (24-hour clock) as a decimal number [00,23].
  • %I โ€” Hour (12-hour clock) as a decimal number [01,12].
  • %j โ€” Day of the year as a decimal number [001,366].
  • %m โ€” Month as a decimal number [01,12].
  • %M โ€” Minute as a decimal number [00,59].
  • %n โ€” A <newline>.
  • %p โ€” Locale's equivalent of either AM or PM.
  • %r โ€” 12-hour clock time [01,12] using the AM/PM notation; in the POSIX locale, this shall be equivalent to %I:%M:%S %p.
  • %S โ€” Seconds as a decimal number [00,60]. (yeah, 60. leap second behavior, she's special ๐Ÿงš)
  • %t โ€” A <tab>.
  • %T โ€” 24-hour clock time [00,23] in the format HH:MM:SS.
  • %u โ€” Weekday as a decimal number [1,7] (1=Monday).
  • %U โ€” Week of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday shall be considered to be in week 0.
  • %V โ€” Week of the year (Monday as the first day of the week) as a decimal number [01,53]. If the week containing January 1 has four or more days in the new year, then it shall be considered week 1; otherwise, it shall be the last week of the previous year, and the next week shall be week 1. (the ISO week girlie. complicated but correct. ๐Ÿ’œ)
  • %w โ€” Weekday as a decimal number [0,6] (0=Sunday).
  • %W โ€” Week of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday shall be considered to be in week 0.
  • %x โ€” Locale's appropriate date representation.
  • %X โ€” Locale's appropriate time representation.
  • %y โ€” Year within century [00,99].
  • %Y โ€” Year with century as a decimal number.
  • %Z โ€” Timezone name, or no characters if no timezone is determinable.
  • %% โ€” A <percent-sign> character.

See the Base Definitions volume of POSIX.1โ€2017, Section 7.3.5, <strong>LC_TIME</strong> for the conversion specifier values in the POSIX locale. ๐Ÿ“š

๐Ÿ’œ Modified Conversion Specifications ๐Ÿ’œ

plot twist!! Some conversion specifiers can be modified by the E and O modifier characters to indicate a <strong>different format or specification</strong>, as specified in the LC_TIME locale description (see the Base Definitions volume of POSIX.1โ€2017, Section 7.3.5, LC_TIME).

And 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 <strong>not specified</strong> or <strong>not supported</strong> for the current locale, then the unmodified conversion specifier value shall be used. fallback queen behavior. ๐Ÿ‘‘

  • %Ec โ€” Locale's alternative appropriate date and time representation.
  • %EC โ€” The name of the base year (period) in the locale's alternative representation.
  • %Ex โ€” Locale's alternative date representation.
  • %EX โ€” Locale's alternative time representation.
  • %Ey โ€” Offset from %EC (year only) in the locale's alternative representation.
  • %EY โ€” Full alternative year representation.
  • %Od โ€” Day of month using the locale's alternative numeric symbols.
  • %Oe โ€” Day of month using the locale's alternative numeric symbols.
  • %OH โ€” Hour (24-hour clock) using the locale's alternative numeric symbols.
  • %OI โ€” Hour (12-hour clock) using the locale's alternative numeric symbols.
  • %Om โ€” Month using the locale's alternative numeric symbols.
  • %OM โ€” Minutes using the locale's alternative numeric symbols.
  • %OS โ€” Seconds using the locale's alternative numeric symbols.
  • %Ou โ€” Weekday as a number in the locale's alternative representation (Monday = 1).
  • %OU โ€” Week number of the year (Sunday as the first day of the week) using the locale's alternative numeric symbols.
  • %OV โ€” Week number of the year (Monday as the first day of the week, rules corresponding to %V), using the locale's alternative numeric symbols.
  • %Ow โ€” Weekday as a number in the locale's alternative representation (Sunday = 0).
  • %OW โ€” Week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols.
  • %Oy โ€” Year (offset from %C) in alternative representation.

๐Ÿซถ mmddhhmm[[cc]yy] ๐Ÿซถ

okay this is the setting the clock operand and it's the one with real stakes, bestie:

Attempt to set the system date and time from the value given in the operand. This is <strong>only possible</strong> if the user has <strong>appropriate privileges</strong> and the system permits the setting of the system date and time.

Breaking it down, character by character, because we love a decode moment:

  • The first mm is the month (number).
  • dd is the day (number).
  • hh is the hour (number, 24-hour system).
  • The second mm is the minute (number).
  • cc is the century and is the first two digits of the year โ€” this is <strong>optional</strong>.
  • yy is the last two digits of the year and is <strong>optional</strong>.

Now the century rules, listen up ๐Ÿ“ข โ€” if century is not specified, then values in the range [69,99] shall refer to years <strong>1969 to 1999</strong> inclusive, and values in the range [00,68] shall refer to years <strong>2000 to 2068</strong> inclusive. The <strong>current year is the default</strong> if yy is omitted.

Note: It is expected that in a future version of this standard the default century inferred from a 2-digit year will change. (This would apply to all commands accepting a 2-digit year as input.) โš ๏ธ so don't build your whole personality around the 1969/2068 split, it's on borrowed time.

๐ŸŒธ STDIN ๐ŸŒธ

Not used. she doesn't read your messages, she only writes. ๐Ÿ’…


๐ŸŒˆ INPUT FILES ๐ŸŒˆ

None. nothing to load, nothing to parse. unbothered.


โญ ENVIRONMENT VARIABLES โญ

The following environment variables shall affect the execution of date:

  • LANG โ€” Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ€2017, Section 8.2, <strong>Internationalization Variables</strong> for the precedence of internationalization variables used to determine the values of locale categories.)
  • LC_ALL โ€” If set to a non-empty string value, override the values of all the other internationalization variables. (the "I said what I said" variable.)
  • LC_CTYPE โ€” Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
  • LC_MESSAGES โ€” Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
  • LC_TIME โ€” Determine the format and contents of date and time strings written by date. (the one that actually changes your output, periodt.)
  • NLSPATH โ€” Determine the location of message catalogs for the processing of LC_MESSAGES.
  • TZ โ€” Determine the timezone in which the time and date are written, unless the -u option is specified. If the TZ variable is unset or null and -u is not specified, an <strong>unspecified system default timezone</strong> is used. (unspecified. we don't know her. ๐Ÿ™ˆ)

๐Ÿงš ASYNCHRONOUS EVENTS ๐Ÿงš

Default.</purl>


๐Ÿ’– STDOUT ๐Ÿ’–

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"

that's the default glow-up, bestie. โœจ


๐ŸŽ€ STDERR ๐ŸŽ€

The standard error shall be used <strong>only</strong> for diagnostic messages. no small talk in the error channel.


๐Ÿฆ‹ OUTPUT FILES ๐Ÿฆ‹

None.


๐Ÿ’œ EXTENDED DESCRIPTION ๐Ÿ’œ

None.


๐Ÿ”ฅ EXIT STATUS ๐Ÿ”ฅ

The following exit values shall be returned:

  • 0 โ€” The date was written successfully. (we ate. ๐ŸŽ‰)
  • >0 โ€” An error occurred. (something went sideways ๐Ÿ’€)

๐ŸŒˆ CONSEQUENCES OF ERRORS ๐ŸŒˆ

Default.


The following sections are informative.

APPLICATION USAGE โœจ

okay bestie, real talk: conversion specifiers are of unspecified format when you're not in the POSIX locale. ๐Ÿ˜ญ And some of them can literally contain <newline> characters in some locales, which means the format shown in standard output can be a whole struggle to use for parsing the output of date in those locales. iykyk.

The range of values for %S extends from 0 to 60 seconds โ€” yes, 60 โ€” to accommodate the occasional leap second. โฑ๏ธโœจ

Even though certain conversion specifiers in the POSIX locale (like the name of the month) are shown with initial capital letters, that need not be the case in other locales. So 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). But %x and %c conversion specifications are intended for local representation โ€” and those 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). You can view it 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 %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. ๐ŸŽ€


EXAMPLES ๐ŸŽ€

  1. The following are input/output examples of date used at arbitrary times in the POSIX locale:
$ 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
  1. Examples for Denmark, where the default date and time format is %a %d %b %Y %T %Z:
$ 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
  1. Examples for Germany, where the default date and time format is %a %d.%h.%Y, %T %Z:
$ 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
  1. Examples for France, where the default date and time format is %a %d %h %Y %Z %T:
$ 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

RATIONALE ๐Ÿ’ญ

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):

  • The historical variety in which Sunday is the first day of the week and the weekdays preceding the first Sunday of the year are considered week 0. These are represented by %w and %U. A variant of this is %W, using Monday as the first day of the week, but still referring to week 0. This view of the calendar was retained because so many historical applications depend on it and the ISO C standard strftime() function, on which many date implementations are based, was defined in this way. ๐Ÿ“œ
  • The international standard, based on the ISO 8601:2004 standard where Monday is the first weekday and the algorithm for the first week number is more complex: If the week (Monday to Sunday) containing January 1 has four or more days in the new year, then it is week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. These are represented by the new conversion specifications %u and %V, added as a result of international comments. ๐ŸŒ

FUTURE DIRECTIONS ๐Ÿ”ฎ

None. ๐Ÿ’€


SEE ALSO ๐Ÿ‘€

  • 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 .


okay bestie that's the whole page ๐Ÿ’– source/version: IEEE/The Open Group, dated 2017, for DATE(1POSIX). go format something cute โœจ

๐Ÿ“ฆ where this page comes from