📄 strftime.html
字号:
<dt><tt>%EY</tt></dt><dd>Replaced by the full alternative year representation.</dd><dt><tt>%Od</tt></dt><dd>Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading zeros if thereis any alternative symbol for zero; otherwise, with leading spaces.</dd><dt><tt>%Oe</tt></dt><dd>Replaced by the day of the month, using the locale's alternative numeric symbols, filled as needed with leading spaces.</dd><dt><tt>%OH</tt></dt><dd>Replaced by the hour (24-hour clock) using the locale's alternative numeric symbols.</dd><dt><tt>%OI</tt></dt><dd>Replaced by the hour (12-hour clock) using the locale's alternative numeric symbols.</dd><dt><tt>%Om</tt></dt><dd>Replaced by the month using the locale's alternative numeric symbols.</dd><dt><tt>%OM</tt></dt><dd>Replaced by the minutes using the locale's alternative numeric symbols.</dd><dt><tt>%OS</tt></dt><dd>Replaced by the seconds using the locale's alternative numeric symbols.</dd><dt><tt>%Ou</tt></dt><dd>Replaced by the weekday as a number in the locale's alternative representation (Monday=1).</dd><dt><tt>%OU</tt></dt><dd>Replaced by the week number of the year (Sunday as the first day of the week, rules corresponding to <tt>%U</tt> ) using thelocale's alternative numeric symbols.</dd><dt><tt>%OV</tt></dt><dd>Replaced by the week number of the year (Monday as the first day of the week, rules corresponding to <tt>%V</tt> ) using thelocale's alternative numeric symbols.</dd><dt><tt>%Ow</tt></dt><dd>Replaced by the number of the weekday (Sunday=0) using the locale's alternative numeric symbols.</dd><dt><tt>%OW</tt></dt><dd>Replaced by the week number of the year (Monday as the first day of the week) using the locale's alternative numericsymbols.</dd><dt><tt>%Oy</tt></dt><dd>Replaced by the year (offset from <tt>%C</tt> ) using the locale's alternative numeric symbols.</dd></dl><p><tt>%g</tt> , <tt>%G</tt> , and <tt>%V</tt> give values according to the ISO 8601:2000 standard week-based year. In thissystem, weeks begin on a Monday and week 1 of the year is the week that includes January 4th, which is also the week that includesthe first Thursday of the year, and is also the first week that contains at least four days in the year. If the first Monday ofJanuary is the 2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year; thus, for Saturday 2nd January1999, <tt>%G</tt> is replaced by 1998 and <tt>%V</tt> is replaced by 53. If December 29th, 30th, or 31st is a Monday, it and anyfollowing days are part of week 1 of the following year. Thus, for Tuesday 30th December 1997, <tt>%G</tt> is replaced by 1998 and<tt>%V</tt> is replaced by 01.</p><p>If a conversion specifier is not one of the above, the behavior is undefined.</p></blockquote><h4><a name="tag_03_729_04"></a>RETURN VALUE</h4><blockquote><p>If the total number of resulting bytes including the terminating null byte is not more than <i>maxsize</i>, <i>strftime</i>()shall return the number of bytes placed into the array pointed to by <i>s</i>, not including the terminating null byte. Otherwise,0 shall be returned and the contents of the array are unspecified.</p></blockquote><h4><a name="tag_03_729_05"></a>ERRORS</h4><blockquote><p>No errors are defined.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_729_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_729_06_01"></a>Getting a Localized Date String</h5><p>The following example first sets the locale to the user's default. The locale information will be used in the <a href="../functions/nl_langinfo.html"><i>nl_langinfo</i>()</a> and <i>strftime</i>() functions. The <a href="../functions/nl_langinfo.html"><i>nl_langinfo</i>()</a> function returns the localized date string which specifies how the date islaid out. The <i>strftime</i>() function takes this information and, using the <b>tm</b> structure for values, places the date andtime information into <i>datestring</i>.</p><pre><tt>#include <time.h>#include <locale.h>#include <langinfo.h>...struct tm *tm;char datestring[256];...setlocale (LC_ALL, "");...strftime (datestring, sizeof(datestring), nl_langinfo (D_T_FMT), tm);...</tt></pre></blockquote><h4><a name="tag_03_729_07"></a>APPLICATION USAGE</h4><blockquote><p>The range of values for <tt>%S</tt> is [00,60] rather than [00,59] to allow for the occasional leap second.</p><p>Some of the conversion specifications are duplicates of others. They are included for compatibility with <i>nl_cxtime</i>() and<i>nl_ascxtime</i>(), which were published in Issue 2.</p><p>Applications should use <tt>%Y</tt> (4-digit years) in preference to <tt>%y</tt> (2-digit years).</p><p>In the C locale, the <tt>E</tt> and <tt>O</tt> modifiers are ignored and the replacement strings for the following specifiersare:</p><dl compact><dt><tt>%a</tt></dt><dd>The first three characters of <tt>%A</tt> .</dd><dt><tt>%A</tt></dt><dd>One of Sunday, Monday, ..., Saturday.</dd><dt><tt>%b</tt></dt><dd>The first three characters of <tt>%B</tt> .</dd><dt><tt>%B</tt></dt><dd>One of January, February, ..., December.</dd><dt><tt>%c</tt></dt><dd>Equivalent to <tt>%a</tt> <tt>%b</tt> <tt>%e</tt> <tt>%T</tt> <tt>%Y</tt> .</dd><dt><tt>%p</tt></dt><dd>One of AM or PM.</dd><dt><tt>%r</tt></dt><dd>Equivalent to <tt>%I</tt> : <tt>%M</tt> : <tt>%S</tt> <tt>%p</tt> .</dd><dt><tt>%x</tt></dt><dd>Equivalent to <tt>%m</tt> / <tt>%d</tt> / <tt>%y</tt> .</dd><dt><tt>%X</tt></dt><dd>Equivalent to <tt>%T</tt> .</dd><dt><tt>%Z</tt></dt><dd>Implementation-defined.</dd></dl></blockquote><h4><a name="tag_03_729_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_729_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_729_10"></a>SEE ALSO</h4><blockquote><p><a href="asctime.html"><i>asctime</i>()</a> , <a href="clock.html"><i>clock</i>()</a> , <a href="ctime.html"><i>ctime</i>()</a>, <a href="difftime.html"><i>difftime</i>()</a> , <a href="getdate.html"><i>getdate</i>()</a> , <a href="gmtime.html"><i>gmtime</i>()</a> , <a href="localtime.html"><i>localtime</i>()</a> , <a href="mktime.html"><i>mktime</i>()</a> ,<a href="strptime.html"><i>strptime</i>()</a> , <a href="time.html"><i>time</i>()</a> , <a href="tzset.html"><i>tzset</i>()</a> ,<a href="utime.html"><i>utime</i>()</a> , Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap07.html#tag_07_03_05">Section 7.3.5, LC_TIME</a>, <a href="../basedefs/time.h.html"><i><time.h></i></a></p></blockquote><h4><a name="tag_03_729_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 3.</p></blockquote><h4><a name="tag_03_729_12"></a>Issue 5</h4><blockquote><p>The description of <tt>%OV</tt> is changed to be consistent with <tt>%V</tt> and defines Monday as the first day of theweek.</p><p>The description of <tt>%Oy</tt> is clarified.</p></blockquote><h4><a name="tag_03_729_13"></a>Issue 6</h4><blockquote><p>Extensions beyond the ISO C standard are marked.</p><p>The Open Group Corrigendum U033/8 is applied. The <tt>%V</tt> conversion specifier is changed from "Otherwise, it is week 53 ofthe previous year, and the next week is week 1" to "Otherwise, it is the last week of the previous year, and the next week isweek 1".</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>The <tt>%C</tt> , <tt>%D</tt> , <tt>%e</tt> , <tt>%h</tt> , <tt>%n</tt> , <tt>%r</tt> , <tt>%R</tt> , <tt>%t</tt> , and<tt>%T</tt> conversion specifiers are added.</p></li><li><p>The modified conversion specifiers are added for consistency with the ISO POSIX-2 standard <a href="../utilities/date.html"><i>date</i></a> utility.</p></li></ul><p>The following changes are made for alignment with the ISO/IEC 9899:1999 standard:</p><ul><li><p>The <i>strftime</i>() prototype is updated.</p></li><li><p>The DESCRIPTION is extensively revised.</p></li><li><p>The <tt>%z</tt> conversion specifier is added.</p></li></ul><p>A new example is added.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XSH/TC1/D6/60 is applied.</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 + -