📄 strftime.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>strftime</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_009_102"> </a>NAME</h4><blockquote>strftime - convert date and time to a string</blockquote><h4><a name = "tag_000_009_103"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="time.h.html">time.h</a>>size_t strftime(char *<i>s</i>, size_t <i>maxsize</i>, const char *<i>format</i>, const struct tm *<i>timptr</i>);</code></pre></blockquote><h4><a name = "tag_000_009_104"> </a>DESCRIPTION</h4><blockquote>The<i>strftime()</i>function places bytes into the array pointed to by<i>s</i>as controlled by the string pointed to by<i>format</i>.The<i>format</i>string consists of zero or more conversion specifications andordinary characters.A conversion specification consists of a % character and a terminatingconversion character that determines the conversion specification'sbehaviour.All ordinary characters (including the terminatingnull byte) are copied unchanged into the array.If copying takes place between objects that overlap, thebehaviour is undefined.No more than<i>maxsize</i>bytes are placed into the array.Each conversion specificationis replaced by appropriate charactersas described in the following list.The appropriate characters are determined by the program's localeand by the values contained in the structure pointed to by<i>timptr</i>.<p>Local timezone information is used as though<i>strftime()</i>called<i><a href="tzset.html">tzset()</a></i>.<dl compact><dt>%a<dd>is replaced by the locale's abbreviated weekday name.<dt>%A<dd>is replaced by the locale's full weekday name.<dt>%b<dd>is replaced by the locale's abbreviated month name.<dt>%B<dd>is replaced by the locale's full month name.<dt>%c<dd>is replaced by the locale's appropriate date and time representation.<dt>%C<dd>is replaced by the century number (the year divided by 100 and truncatedto an integer) as a decimal number [00-99].<dt>%d<dd>is replaced by the day of the month as a decimal number [01,31].<dt>%D<dd>same as %m/%d/%y.<dt>%e<dd>is replaced by the day of the month as a decimal number [1,31];a single digit is preceded by a space.<dt>%h<dd>same as %b.<dt>%H<dd>is replaced by the hour (24-hour clock) as a decimal number [00,23].<dt>%I<dd>is replaced by the hour (12-hour clock) as a decimal number [01,12].<dt>%j<dd>is replaced by the day of the year as a decimal number [001,366].<dt>%m<dd>is replaced by the month as a decimal number [01,12].<dt>%M<dd>is replaced by the minute as a decimal number [00,59].<dt>%n<dd>is replaced by a newline character.<dt>%p<dd>is replaced by the locale's equivalent of either a.m. or p.m.<dt>%r<dd>is replaced by the time in a.m. andp.m. notation; in the POSIX locale this isequivalent to %I:%M:%S %p.<dt>%R<dd>is replaced by the time in 24 hour notation (%H:%M).<dt>%S<dd>is replaced by the second as a decimal number [00,61].<dt>%t<dd>is replaced by a tab character.<dt>%T<dd>is replaced by the time (%H:%M:%S).<dt>%u<dd>is replaced by the weekday as a decimal number [1,7], with 1 representingMonday.<dt>%U<dd>is replaced by the week number of the year (Sunday as the first day ofthe week) as a decimal number [00,53].<dt>%V<dd>is replaced by the week number of the year (Monday as the first day of theweek) as a decimal number [01,53]. If the week containing 1 January hasfour or more days in the new year, then it is considered week 1. Otherwise,it is the last week of the previous year, and the next week is week 1.<dt>%w<dd>is replaced by the weekday as a decimal number [0,6], with 0 representingSunday.<dt>%W<dd>is replaced by the week number of the year (Monday as the first day ofthe week) as a decimal number [00,53]. All days in a new year precedingthe first Monday are considered to be in week 0.<dt>%x<dd>is replaced by the locale's appropriate date representation.<dt>%X<dd>is replaced by the locale's appropriate time representation.<dt>%y<dd>is replaced by the year without century as a decimal number [00,99].<dt>%Y<dd>is replaced by the year with century as a decimal number.<dt>%Z<dd>is replaced by the timezone name or abbreviation, or by no bytesif no timezoneinformation exists.<dt>%%<dd>is replaced by %.</dl><p>If a conversion specification does not correspond to anyof the above, the behaviour is undefined.<h5><a name = "tag_000_009_104_001"> </a>Modified Conversion Specifiers</h5>Some conversion specifiers can be modified by the E or O modifier charactersto indicate that an alternative format or specification should be used ratherthan the one normally used by the unmodified conversion specifier. If thealternative format or specification does not exist for the current locale,(see ERA in the <b>XBD</b> specification, <b>Section 5.3.5</b>)the behaviour will be as if the unmodified conversion specification wereused.<dl compact><dt>%Ec<dd>is replaced by the locale's alternative appropriate date andtime representation.<dt>%EC<dd>is replaced by the name of the base year (period) in thelocale's alternative representation.<dt>%Ex<dd>is replaced by the locale's alternative date representation.<dt>%EX<dd>is replaced by the locale' alternative time representation.<dt>%Ey<dd>is replaced by the offset from %EC (year only) in the locale'salternative representation.<dt>%EY<dd>is replaced by the full alternative year representation.<dt>%Od<dd>is replaced by the day of the month, using the locale'salternative numeric symbols, filled as needed with leading zeros if there isany alternative symbol for zero, otherwise with leading spaces.<dt>%Oe<dd>is replaced by the day of month, using the locale'salternative numeric symbols, filled as needed with leading spaces.<dt>%OH<dd>is replaced by the hour (24-hour clock) using the locale'salternative numeric symbols.<dt>%OI<dd>is replaced by the hour (12-hour clock) using the locale'salternative numeric symbols.<dt>%Om<dd>is replaced by the month using the locale's alternative numericsymbols.<dt>%OM<dd>is replaced by the minutes using the locale's alternative numericsymbols.<dt>%OS<dd>is replaced by the seconds using the locale's alternative numericsymbols.<dt>%Ou<dd>is replaced by the weekday as a number in the locale's alternativerepresentation (Monday=1).<dt>%OU<dd>is replaced by the week number of the year (Sunday as the firstday of the week, rules corresponding to %U)using the locale's alternative numeric symbols.<dt>%OV<dd>is replaced by the week number of the year (Monday as the firstday of the week, rules corresponding to %V)using the locale's alternative numeric symbols.<dt>%Ow<dd>is replaced by the number of the weekday (Sunday=0) usingthe locale's alternative numeric symbols.<dt>%OW<dd>is replaced by the week number of the year (Monday as the firstday of the week) using the locale's alternative numeric symbols.<dt>%Oy<dd>is replaced by the year (offset from %C) using the locale'salternative numeric symbols.</dl></blockquote><h4><a name = "tag_000_009_105"> </a>RETURN VALUE</h4><blockquote>If the total number of resulting bytes including the terminatingnull byte is not more than<i>maxsize</i>,<i>strftime()</i>returns the number of bytes placed into the array pointed to by<i>s</i>,not including the terminating null byte. Otherwise, 0 is returned and thecontents of the array are indeterminate.</blockquote><h4><a name = "tag_000_009_106"> </a>ERRORS</h4><blockquote>No errors are defined.</blockquote><h4><a name = "tag_000_009_107"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_009_108"> </a>APPLICATION USAGE</h4><blockquote>The range of values for %S is [00,61] rather than [00,59] to allowfor the occasional leap second and even more infrequent double leap second.<p>Some of the conversion specificationsmarked EX 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>Applications should use %Y (4-digit years) in preference to %y(2-digit years).</blockquote><h4><a name = "tag_000_009_109"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_009_110"> </a>SEE ALSO</h4><blockquote><i><a href="asctime.html">asctime()</a></i>,<i><a href="clock.html">clock()</a></i>,<i><a href="ctime.html">ctime()</a></i>,<i><a href="difftime.html">difftime()</a></i>,<i><a href="gmtime.html">gmtime()</a></i>,<i><a href="localtime.html">localtime()</a></i>,<i><a href="mktime.html">mktime()</a></i>,<i><a href="strptime.html">strptime()</a></i>,<i><a href="time.html">time()</a></i>,<i><a href="utime.html">utime()</a></i>,<i><a href="time.h.html"><time.h></a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -