diff options
Diffstat (limited to 'devdocs/c/chrono%2Fasctime.html')
| -rw-r--r-- | devdocs/c/chrono%2Fasctime.html | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/devdocs/c/chrono%2Fasctime.html b/devdocs/c/chrono%2Fasctime.html new file mode 100644 index 00000000..436673de --- /dev/null +++ b/devdocs/c/chrono%2Fasctime.html @@ -0,0 +1,85 @@ + <h1 id="firstHeading" class="firstHeading">asctime, asctime_s</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><time.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl-rev-aux"> <td></td> <td rowspan="3">(1)</td> <td></td> </tr> <tr class="t-dcl t-until-c23"> <td><pre data-language="c">char* asctime( const struct tm* time_ptr );</pre></td> <td><span class="t-mark-rev t-until-c23">(until C23)</span></td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">[[deprecated]] char* asctime( const struct tm* time_ptr );</pre> +</td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> <tr class="t-dcl t-since-c11"> <td> <pre data-language="c">errno_t asctime_s( char* buf, rsize_t bufsz, const struct tm* time_ptr );</pre> +</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <span class="t-li">1)</span> Converts given calendar time <code><a href="tm" title="c/chrono/tm">tm</a></code> to a textual representation of the following fixed 25-character form: <code>Www Mmm dd hh:mm:ss yyyy\n</code> <ul> +<li> +<code>Www</code> - three-letter English abbreviated day of the week from <code>time_ptr->tm_wday</code>, one of <code>Mon</code>, <code>Tue</code>, <code>Wed</code>, <code>Thu</code>, <code>Fri</code>, <code>Sat</code>, <code>Sun</code>. </li> +<li> +<code>Mmm</code> - three-letter English abbreviated month name from <code>time_ptr->tm_mon</code>, one of <code>Jan</code>, <code>Feb</code>, <code>Mar</code>, <code>Apr</code>, <code>May</code>, <code>Jun</code>, <code>Jul</code>, <code>Aug</code>, <code>Sep</code>, <code>Oct</code>, <code>Nov</code>, <code>Dec</code>. </li> +<li> +<code>dd</code> - 2-digit day of the month from <code>timeptr->tm_mday</code> as if printed by <code><a href="../io/fprintf" title="c/io/fprintf">sprintf</a></code> using <code>%2d</code> </li> +<li> +<code>hh</code> - 2-digit hour from <code>timeptr->tm_hour</code> as if printed by <code><a href="../io/fprintf" title="c/io/fprintf">sprintf</a></code> using <code>%.2d</code> </li> +<li> +<code>mm</code> - 2-digit minute from <code>timeptr->tm_min</code> as if printed by <code><a href="../io/fprintf" title="c/io/fprintf">sprintf</a></code> using <code>%.2d</code> </li> +<li> +<code>ss</code> - 2-digit second from <code>timeptr->tm_sec</code> as if printed by <code><a href="../io/fprintf" title="c/io/fprintf">sprintf</a></code> using <code>%.2d</code> </li> +<li> +<code>yyyy</code> - 4-digit year from <code>timeptr->tm_year + 1900</code> as if printed by <code><a href="../io/fprintf" title="c/io/fprintf">sprintf</a></code> using <code>%4d</code> +</li> +</ul> <div class="t-li1"> + The behavior is undefined if any member of <code>*time_ptr</code> is outside its normal range</div> <div class="t-li1"> + The behavior is undefined if the calendar year indicated by <code>time_ptr->tm_year</code> has more than 4 digits or is less than the year 1000.</div> <div class="t-li1"> + The function does not support localization, and the newline character cannot be removed.</div> <div class="t-li1"> + The function modifies static storage and is not thread-safe.</div> <table class="t-rev-begin"> <tr class="t-rev t-since-c23"> +<td> This function is deprecated and should not be used in new code. </td> <td><span class="t-mark-rev t-since-c23">(since C23)</span></td> +</tr> </table> <div class="t-li1"> +<span class="t-li">2)</span> Same as <span class="t-v">(1)</span>, except that the message is written into user-provided storage <code>buf</code>, which is guaranteed to be null-terminated, and the following errors are detected at runtime and call the currently installed <a href="../error/set_constraint_handler_s" title="c/error/set constraint handler s">constraint handler</a> function: <dl> +<dd> +<ul> +<li> <code>buf</code> or <code>time_ptr</code> is a null pointer </li> +<li> <code>bufsz</code> is less than 26 or greater than <code>RSIZE_MAX</code> </li> +<li> not all members of <code>*time_ptr</code> are within their normal ranges </li> +<li> the year indicated by <code>time_ptr->tm_year</code> is less than 0 or greater than 9999 </li> +</ul> </dd> +<dd>As with all bounds-checked functions, <code>asctime_s</code> only guaranteed to be available if <code>__STDC_LIB_EXT1__</code> is defined by the implementation and if the user defines <code>__STDC_WANT_LIB_EXT1__</code> to the integer constant <code>1</code> before including <a href="../chrono" title="c/chrono"><code><time.h></code></a>.</dd> +</dl> +</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> time_ptr </td> <td> - </td> <td> pointer to a <code><a href="tm" title="c/chrono/tm">tm</a></code> object specifying the time to print </td> +</tr> <tr class="t-par"> <td> buf </td> <td> - </td> <td> pointer to a user-supplied buffer at least 26 bytes in length </td> +</tr> <tr class="t-par"> <td> bufsz </td> <td> - </td> <td> size of the user-supplied buffer </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <div class="t-li1"> +<span class="t-li">1)</span> pointer to a static null-terminated character string holding the textual representation of date and time as described above. The string may be shared between <code>asctime</code> and <code><a href="ctime" title="c/chrono/ctime">ctime</a></code>, and may be overwritten on each invocation of any of those functions.</div> <div class="t-li1"> +<span class="t-li">2)</span> zero on success, non-zero on failure, in which case <code>buf[0]</code> is set to zero (unless <code>buf</code> is a null pointer or <code>bufsz</code> is zero or greater than <code>RSIZE_MAX</code>).</div> <h3 id="Notes"> Notes</h3> <p><code>asctime</code> returns a pointer to static data and is not thread-safe. POSIX marks this function obsolete and recommends <code><a href="strftime" title="c/chrono/strftime">strftime</a></code> instead. The C standard also recommends <code><a href="strftime" title="c/chrono/strftime">strftime</a></code> instead of <code>asctime</code> and <code>asctime_s</code> because <code>strftime</code> is more flexible and locale-sensitive.</p> +<p>POSIX limits undefined behaviors only to when the output string would be longer than 25 characters, when <code>timeptr->tm_wday</code> or <code>timeptr->tm_mon</code> are not within the expected ranges, or when <code>timeptr->tm_year</code> exceeds <code>INT_MAX-1990</code>.</p> +<p>Some implementations handle <code>timeptr->tm_mday==0</code> as meaning the last day of the preceding month.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#define __STDC_WANT_LIB_EXT1__ 1 +#include <time.h> +#include <stdio.h> + +int main(void) +{ + struct tm tm = *localtime(&(time_t){time(NULL)}); + printf("%s", asctime(&tm)); + +#ifdef __STDC_LIB_EXT1__ + char str[26]; + asctime_s(str, sizeof str, &tm); + printf("%s", str); +#endif +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">Tue May 26 21:51:50 2015 +Tue May 26 21:51:50 2015</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul> +<li> 7.27.2.1 The asctime function (p: 287) </li> +<li> K.3.8.2.1 The asctime_s function (p: 453-454) </li> +</ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.27.2.1 The asctime function (p: 392-393) </li> +<li> K.3.8.2.1 The asctime_s function (p: 624-625) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.23.3.1 The asctime function (p: 341-342) </li></ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 4.12.3.1 The asctime function </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="ctime" title="c/chrono/ctime"> <span class="t-lines"><span>ctime</span><span>ctime_s</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-deprecated-c23">(deprecated in C23)</span></span><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> converts a <code><a href="time_t" title="c/chrono/time t">time_t</a></code> object to a textual representation <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="strftime" title="c/chrono/strftime"> <span class="t-lines"><span>strftime</span></span></a></div> </td> <td> converts a <code><a href="tm" title="c/chrono/tm">tm</a></code> object to custom textual representation <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/chrono/c/asctime" title="cpp/chrono/c/asctime">C++ documentation</a></span> for <code>asctime</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/chrono/asctime" class="_attribution-link">https://en.cppreference.com/w/c/chrono/asctime</a> + </p> +</div> |
