⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strftime.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>strftime</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="strftime"></a> <a name="tag_03_729"></a><!-- strftime --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_729_01"></a>NAME</h4><blockquote>strftime - convert date and time to a string</blockquote><h4><a name="tag_03_729_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/time.h.html">time.h</a>&gt;<br><br> size_t strftime(char *restrict</tt> <i>s</i><tt>, size_t</tt> <i>maxsize</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char *restrict</tt> <i>format</i><tt>, const struct tm *restrict</tt><i>timeptr</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_729_03"></a>DESCRIPTION</h4><blockquote><div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"border="0"> The functionality described on this reference page is aligned with the ISO&nbsp;C standard. Any conflict between therequirements described here and the ISO&nbsp;C standard is unintentional. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 defers tothe ISO&nbsp;C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div><p>The <i>strftime</i>() function shall place bytes into the array pointed to by <i>s</i> as controlled by the string pointed to by<i>format</i>. The format is a character string, beginning and ending in its initial shift state, if any. The <i>format</i> stringconsists of zero or more conversion specifications and ordinary characters. A conversion specification consists of a <tt>'%'</tt>character, possibly followed by an <tt>E</tt> or <tt>O</tt> modifier, and a terminating conversion specifier character thatdetermines the conversion specification's behavior. All ordinary characters (including the terminating null byte) are copiedunchanged into the array. If copying takes place between objects that overlap, the behavior is undefined. No more than<i>maxsize</i> bytes are placed into the array. Each conversion specifier is replaced by appropriate characters as described in thefollowing list. The appropriate characters are determined using the <i>LC_TIME</i> category of the current locale and by the valuesof zero or more members of the broken-down time structure pointed to by <i>timeptr</i>, as specified in brackets in thedescription. If any of the specified values are outside the normal range, the characters stored are unspecified.</p><p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Local timezone information is used as though <i>strftime</i>() called <a href="../functions/tzset.html"><i>tzset</i>()</a>. <imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>The following conversion specifications are supported:</p><dl compact><dt><tt>%a</tt></dt><dd>Replaced by the locale's abbreviated weekday name. [ <i>tm_wday</i>]</dd><dt><tt>%A</tt></dt><dd>Replaced by the locale's full weekday name. [ <i>tm_wday</i>]</dd><dt><tt>%b</tt></dt><dd>Replaced by the locale's abbreviated month name. [ <i>tm_mon</i>]</dd><dt><tt>%B</tt></dt><dd>Replaced by the locale's full month name. [ <i>tm_mon</i>]</dd><dt><tt>%c</tt></dt><dd>Replaced by the locale's appropriate date and time representation. (See the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/time.h.html"><i>&lt;time.h&gt;</i></a>.)</dd><dt><tt>%C</tt></dt><dd>Replaced by the year divided by 100 and truncated to an integer, as a decimal number [00,99]. [ <i>tm_year</i>]</dd><dt><tt>%d</tt></dt><dd>Replaced by the day of the month as a decimal number [01,31]. [ <i>tm_mday</i>]</dd><dt><tt>%D</tt></dt><dd>Equivalent to <tt>%m</tt> / <tt>%d</tt> / <tt>%y</tt> . [ <i>tm_mon</i>, <i>tm_mday</i>, <i>tm_year</i>]</dd><dt><tt>%e</tt></dt><dd>Replaced by the day of the month as a decimal number [1,31]; a single digit is preceded by a space. [ <i>tm_mday</i>]</dd><dt><tt>%F</tt></dt><dd>Equivalent to <tt>%Y</tt> - <tt>%m</tt> - <tt>%d</tt> (the ISO&nbsp;8601:2000 standard date format). [ <i>tm_year</i>,<i>tm_mon</i>, <i>tm_mday</i>]</dd><dt><tt>%g</tt></dt><dd>Replaced by the last 2 digits of the week-based year (see below) as a decimal number [00,99]. [ <i>tm_year</i>, <i>tm_wday</i>,<i>tm_yday</i>]</dd><dt><tt>%G</tt></dt><dd>Replaced by the week-based year (see below) as a decimal number (for example, 1977). [ <i>tm_year</i>, <i>tm_wday</i>,<i>tm_yday</i>]</dd><dt><tt>%h</tt></dt><dd>Equivalent to <tt>%b</tt> . [ <i>tm_mon</i>]</dd><dt><tt>%H</tt></dt><dd>Replaced by the hour (24-hour clock) as a decimal number [00,23]. [ <i>tm_hour</i>]</dd><dt><tt>%I</tt></dt><dd>Replaced by the hour (12-hour clock) as a decimal number [01,12]. [ <i>tm_hour</i>]</dd><dt><tt>%j</tt></dt><dd>Replaced by the day of the year as a decimal number [001,366]. [ <i>tm_yday</i>]</dd><dt><tt>%m</tt></dt><dd>Replaced by the month as a decimal number [01,12]. [ <i>tm_mon</i>]</dd><dt><tt>%M</tt></dt><dd>Replaced by the minute as a decimal number [00,59]. [ <i>tm_min</i>]</dd><dt><tt>%n</tt></dt><dd>Replaced by a &lt;newline&gt;.</dd><dt><tt>%p</tt></dt><dd>Replaced by the locale's equivalent of either a.m. or p.m. [ <i>tm_hour</i>]</dd><dt><tt>%r</tt></dt><dd>Replaced by the time in a.m. and p.m. notation; <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> &nbsp;in the POSIX locale this shall be equivalent to <tt>%I</tt> :<tt>%M</tt> : <tt>%S</tt> <tt>%p</tt> . <img src="../images/opt-end.gif" alt="[Option End]" border="0"> [ <i>tm_hour</i>,<i>tm_min</i>, <i>tm_sec</i>]</dd><dt><tt>%R</tt></dt><dd>Replaced by the time in 24-hour notation ( <tt>%H</tt> : <tt>%M</tt> ). [ <i>tm_hour</i>, <i>tm_min</i>]</dd><dt><tt>%S</tt></dt><dd>Replaced by the second as a decimal number [00,60]. [ <i>tm_sec</i>]</dd><dt><tt>%t</tt></dt><dd>Replaced by a &lt;tab&gt;.</dd><dt><tt>%T</tt></dt><dd>Replaced by the time ( <tt>%H</tt> : <tt>%M</tt> : <tt>%S</tt> ). [ <i>tm_hour</i>, <i>tm_min</i>, <i>tm_sec</i>]</dd><dt><tt>%u</tt></dt><dd>Replaced by the weekday as a decimal number [1,7], with 1 representing Monday. [ <i>tm_wday</i>]</dd><dt><tt>%U</tt></dt><dd>Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the first day of week 1;days in the new year before this are in week 0. [ <i>tm_year</i>, <i>tm_wday</i>, <i>tm_yday</i>]</dd><dt><tt>%V</tt></dt><dd>Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53]. If the weekcontaining 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of theprevious year, and the next week is week 1. Both January 4th and the first Thursday of January are always in week 1. [<i>tm_year</i>, <i>tm_wday</i>, <i>tm_yday</i>]</dd><dt><tt>%w</tt></dt><dd>Replaced by the weekday as a decimal number [0,6], with 0 representing Sunday. [ <i>tm_wday</i>]</dd><dt><tt>%W</tt></dt><dd>Replaced by the week number of the year as a decimal number [00,53]. The first Monday of January is the first day of week 1;days in the new year before this are in week 0. [ <i>tm_year</i>, <i>tm_wday</i>, <i>tm_yday</i>]</dd><dt><tt>%x</tt></dt><dd>Replaced by the locale's appropriate date representation. (See the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001,<a href="../basedefs/time.h.html"><i>&lt;time.h&gt;</i></a>.)</dd><dt><tt>%X</tt></dt><dd>Replaced by the locale's appropriate time representation. (See the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001,<a href="../basedefs/time.h.html"><i>&lt;time.h&gt;</i></a>.)</dd><dt><tt>%y</tt></dt><dd>Replaced by the last two digits of the year as a decimal number [00,99]. [ <i>tm_year</i>]</dd><dt><tt>%Y</tt></dt><dd>Replaced by the year as a decimal number (for example, 1997). [ <i>tm_year</i>]</dd><dt><tt>%z</tt></dt><dd>Replaced by the offset from UTC in the ISO&nbsp;8601:2000 standard format ( <tt>+hhmm</tt> or <tt>-hhmm</tt> ), or by nocharacters if no timezone is determinable. For example, <tt>"-0430"</tt> means 4 hours 30 minutes behind UTC (west of Greenwich).<sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">&nbsp;If <i>tm_isdst</i> is zero, the standard time offset is used. If <i>tm_isdst</i> is greater than zero, the daylight savingstime offset is used. If <i>tm_isdst</i> is negative, no characters are returned. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> [ <i>tm_isdst</i>]</dd><dt><tt>%Z</tt></dt><dd>Replaced by the timezone name or abbreviation, or by no bytes if no timezone information exists. [ <i>tm_isdst</i>]</dd><dt><tt>%%</tt></dt><dd>Replaced by <tt>%</tt> .</dd></dl><p>If a conversion specification does not correspond to any of the above, the behavior is undefined.</p><p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Ifa <b>struct tm</b> broken-down time structure is created by <a href="../functions/localtime.html"><i>localtime</i>()</a> or <ahref="../functions/localtime_r.html"><i>localtime_r</i>()</a>, or modified by <a href="../functions/mktime.html"><i>mktime</i>()</a>, and the value of <i>TZ</i> is subsequently modified, the results of the <tt>%Z</tt>and <tt>%z</tt> <i>strftime</i>() conversion specifiers are undefined, when <i>strftime</i>() is called with such a broken-downtime structure.</p><p>If a <b>struct tm</b> broken-down time structure is created or modified by <a href="../functions/gmtime.html"><i>gmtime</i>()</a> or <a href="../functions/gmtime_r.html"><i>gmtime_r</i>()</a>, it is unspecifiedwhether the result of the <tt>%Z</tt> and <tt>%z</tt> conversion specifiers shall refer to UTC or the current local timezone, when<i>strftime</i>() is called with such a broken-down time structure. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><h5><a name="tag_03_729_03_01"></a>Modified Conversion Specifiers</h5><p>Some conversion specifiers can be modified by the <tt>E</tt> or <tt>O</tt> modifier characters to indicate that an alternativeformat or specification should be used rather than the one normally used by the unmodified conversion specifier. If the alternativeformat or specification does not exist for the current locale (see ERA in the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap07.html#tag_07_03_05">Section 7.3.5, LC_TIME</a>), the behavior shallbe as if the unmodified conversion specification were used.</p><dl compact><dt><tt>%Ec</tt></dt><dd>Replaced by the locale's alternative appropriate date and time representation.</dd><dt><tt>%EC</tt></dt><dd>Replaced by the name of the base year (period) in the locale's alternative representation.</dd><dt><tt>%Ex</tt></dt><dd>Replaced by the locale's alternative date representation.</dd><dt><tt>%EX</tt></dt><dd>Replaced by the locale's alternative time representation.</dd><dt><tt>%Ey</tt></dt><dd>Replaced by the offset from <tt>%EC</tt> (year only) in the locale's alternative representation.</dd>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -