📄 date.html
字号:
<blockquote><p>Not used.</p></blockquote><h4><a name="tag_04_33_07"></a>INPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_33_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>date</i>:</p><dl compact><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments).</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standarderror.</dd><dt><i>LC_TIME</i></dt><dd>Determine the format and contents of date and time strings written by <i>date</i>.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt><i>TZ</i></dt><dd>Determine the timezone in which the time and date are written, unless the <b>-u</b> option is specified. If the <i>TZ</i>variable is unset or null and <b>-u</b> is not specified, an unspecified system default timezone is used.</dd></dl></blockquote><h4><a name="tag_04_33_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_33_10"></a>STDOUT</h4><blockquote><p>When no formatting operand is specified, the output in the POSIX locale shall be equivalent to specifying:</p><pre><tt>date "+%a %b %e %H:%M:%S %Z %Y"</tt></pre></blockquote><h4><a name="tag_04_33_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_33_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_33_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_33_14"></a>EXIT STATUS</h4><blockquote><p>The following exit values shall be returned:</p><dl compact><dt> 0</dt><dd>The date was written successfully.</dd><dt>>0</dt><dd>An error occurred.</dd></dl></blockquote><h4><a name="tag_04_33_15"></a>CONSEQUENCES OF ERRORS</h4><blockquote><p>Default.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_04_33_16"></a>APPLICATION USAGE</h4><blockquote><p>Conversion specifiers are of unspecified format when not in the POSIX locale. Some of them can contain <newline>s in somelocales, so it may be difficult to use the format shown in standard output for parsing the output of <i>date</i> in thoselocales.</p><p>The range of values for <tt>%S</tt> extends from 0 to 60 seconds to accommodate the occasional leap second.</p><p>Although certain of the conversion specifiers in the POSIX locale (such as the name of the month) are shown with initial capitalletters, this need not be the case in other locales. Programs using these fields may need to adjust the capitalization if theoutput is going to be used at the beginning of a sentence.</p><p>The date string formatting capabilities are intended for use in Gregorian-style calendars, possibly with a different startingyear (or years). The <tt>%x</tt> and <tt>%c</tt> conversion specifications, however, are intended for local representation; thesemay be based on a different, non-Gregorian calendar.</p><p>The <tt>%C</tt> conversion specification was introduced to allow a fallback for the <tt>%EC</tt> (alternative year format baseyear); it can be viewed as the base of the current subdivision in the Gregorian calendar. The century number is calculated as theyear divided by 100 and truncated to an integer; it should not be confused with the use of ordinal numbers for centuries (forexample, "twenty-first century".) Both the <tt>%Ey</tt> and <tt>%y</tt> can then be viewed as the offset from <tt>%EC</tt> and<tt>%C</tt> , respectively.</p><p>The <tt>E</tt> and <tt>O</tt> modifiers modify the traditional conversion specifiers, so that they can always be used, even ifthe implementation (or the current locale) does not support the modifier.</p><p>The <tt>E</tt> modifier supports alternative date formats, such as the Japanese Emperor's Era, as long as these are based on theGregorian calendar system. Extending the <tt>E</tt> modifiers to other date elements may provide an implementation-definedextension capable of supporting other calendar systems, especially in combination with the <tt>O</tt> modifier.</p><p>The <tt>O</tt> modifier supports time and date formats using the locale's alternative numerical symbols, such as Kanji or Hindidigits or ordinal number representation.</p><p>Non-European locales, whether they use Latin digits in computational items or not, often have local forms of the digits for usein date formats. This is not totally unknown even in Europe; a variant of dates uses Roman numerals for the months: the third dayof 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 <tt>%d</tt> , <tt>%e</tt> , <tt>%H</tt> , <tt>%I</tt> , <tt>%m</tt> , <tt>%S</tt> , <tt>%U</tt> ,<tt>%w</tt> , <tt>%W</tt> , and <tt>%y</tt> conversion specifications always return the date and time field in Latin digits (thatis, 0 to 9). The <tt>%O</tt> modifier was introduced to support the use for display purposes of non-Latin digits. In the<i>LC_TIME</i> category in <a href="../utilities/localedef.html"><i>localedef</i></a>, the optional <b>alt_digits</b> keyword isintended for this purpose. As an example, assume the following (partial) <a href="../utilities/localedef.html"><i>localedef</i></a>source:</p><pre><tt>alt_digits "";"I";"II";"III";"IV";"V";"VI";"VII";"VIII" \ "IX";"X";"XI";"XII"d_fmt "%e.%Om.%Y"</tt></pre><p>With the above date, the command:</p><pre><tt>date "+%x"</tt></pre><p>would yield 3.IX.1991. With the same <b>d_fmt</b>, but without the <b>alt_digits</b>, the command would yield 3.9.1991.</p></blockquote><h4><a name="tag_04_33_17"></a>EXAMPLES</h4><blockquote><ol><li><p>The following are input/output examples of <i>date</i> used at arbitrary times in the POSIX locale:</p><pre><b>$</b> <tt>date</tt><b>Tue Jun 26 09:58:10 PDT 1990<br>$</b> <tt>date "+DATE: %m/%d/%y%nTIME: %H:%M:%S"</tt><b>DATE: 11/02/91TIME: 13:36:16<br>$</b> <tt>date "+TIME: %r"</tt><b>TIME: 01:36:32 PM</b></pre></li><li><p>Examples for Denmark, where the default date and time format is <tt>%a</tt> <tt>%d</tt> <tt>%b</tt> <tt>%Y</tt> <tt>%T</tt><tt>%Z</tt> :</p><pre><b>$</b> <tt>LANG=da_DK.iso_8859-1 date</tt><b>ons 02 okt 1991 15:03:32 CET<br>$</b> <tt>LANG=da_DK.iso_8859-1 \ date "+DATO: %A den %e. %B %Y%nKLOKKEN: %H:%M:%S"</tt><b>DATO: onsdag den 2. oktober 1991KLOKKEN: 15:03:56</b></pre></li><li><p>Examples for Germany, where the default date and time format is <tt>%a</tt> <tt>%d</tt> . <tt>%h</tt> . <tt>%Y</tt> ,<tt>%T</tt> <tt>%Z</tt> :</p><pre><b>$</b> <tt>LANG=De_DE.88591 date</tt><b>Mi 02.Okt.1991, 15:01:21 MEZ<br>$</b> <tt>LANG=De_DE.88591 date "+DATUM: %A, %d. %B %Y%nZEIT: %H:%M:%S"</tt><b>DATUM: Mittwoch, 02. Oktober 1991ZEIT: 15:02:02</b></pre></li><li><p>Examples for France, where the default date and time format is <tt>%a</tt> <tt>%d</tt> <tt>%h</tt> <tt>%Y</tt> <tt>%Z</tt><tt>%T</tt> :</p><pre><b>$</b> <tt>LANG=Fr_FR.88591 date</tt><b>Mer 02 oct 1991 MET 15:03:32<br>$</b> <tt>LANG=Fr_FR.88591 date "+JOUR: %A %d %B %Y%nHEURE: %H:%M:%S"</tt><b>JOUR: Mercredi 02 octobre 1991HEURE: 15:03:56</b></pre></li></ol></blockquote><h4><a name="tag_04_33_18"></a>RATIONALE</h4><blockquote><p>Some of the new options for formatting are from the ISO C standard. The <b>-u</b> option was introduced to allow portableaccess to Coordinated Universal Time (UTC). The string <tt>"GMT0"</tt> is allowed as an equivalent <i>TZ</i> value to be compatiblewith all of the systems using the BSD implementation, where this option originated.</p><p>The <tt>%e</tt> format conversion specification (adopted from System V) was added because the ISO C standard conversionspecifications did not provide any way to produce the historical default <i>date</i> output during the first nine days of anymonth.</p><p>There are two varieties of day and week numbering supported (in addition to any others created with the locale-dependent<tt>%E</tt> and <tt>%O</tt> modifier characters):</p><ul><li><p>The historical variety in which Sunday is the first day of the week and the weekdays preceding the first Sunday of the year areconsidered week 0. These are represented by <tt>%w</tt> and <tt>%U</tt> . A variant of this is <tt>%W</tt> , using Monday as thefirst day of the week, but still referring to week 0. This view of the calendar was retained because so many historicalapplications depend on it and the ISO C standard <a href="../functions/strftime.html"><i>strftime</i>()</a> function, on whichmany <i>date</i> implementations are based, was defined in this way.</p></li><li><p>The international standard, based on the ISO 8601:2000 standard where Monday is the first weekday and the algorithm for thefirst week number is more complex: If the week (Monday to Sunday) containing January 1 has four or more days in the new year, thenit is week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. These are represented by the newconversion specifications <tt>%u</tt> and <tt>%V</tt> , added as a result of international comments.</p></li></ul></blockquote><h4><a name="tag_04_33_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_33_20"></a>SEE ALSO</h4><blockquote><p>The System Interfaces volume of IEEE Std 1003.1-2001, <a href="../functions/printf.html"><i>printf</i>()</a>, <a href="../functions/strftime.html"><i>strftime</i>()</a></p></blockquote><h4><a name="tag_04_33_21"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2.</p></blockquote><h4><a name="tag_04_33_22"></a>Issue 5</h4><blockquote><p>Changes are made for Year 2000 alignment.</p></blockquote><h4><a name="tag_04_33_23"></a>Issue 6</h4><blockquote><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>The <tt>%EX</tt> modified conversion specification is added.</p></li></ul><p>The Open Group Corrigendum U048/2 is applied, correcting the examples.</p><p>The DESCRIPTION is updated to refer to conversion specifications, instead of field descriptors for consistency with the<i>LC_TIME</i> category.</p><p>A clarification is made such that the current year is the default if the <i>yy</i> argument is omitted when setting the systemdate and time.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XCU/TC1/D6/19 is applied, correcting the CHANGE HISTORY section.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -