diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/chrono%2Fctime.html | |
new repository
Diffstat (limited to 'devdocs/c/chrono%2Fctime.html')
| -rw-r--r-- | devdocs/c/chrono%2Fctime.html | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/devdocs/c/chrono%2Fctime.html b/devdocs/c/chrono%2Fctime.html new file mode 100644 index 00000000..f68df0e7 --- /dev/null +++ b/devdocs/c/chrono%2Fctime.html @@ -0,0 +1,79 @@ + <h1 id="firstHeading" class="firstHeading">ctime, ctime_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* ctime( const time_t* timer );</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* ctime( const time_t* timer );</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 ctime_s( char *buf, rsize_t bufsz, const time_t* timer );</pre> +</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <div class="t-li1"> +<span class="t-li">1)</span> Converts given time since epoch to a calendar local time and then to a textual representation, as if by calling <code><a href="http://en.cppreference.com/w/c/chrono/asctime"><span class="kw515">asctime</span></a><span class="br0">(</span><a href="http://en.cppreference.com/w/c/chrono/localtime"><span class="kw519">localtime</span></a><span class="br0">(</span>timer<span class="br0">)</span><span class="br0">)</span></code><span class="t-rev-inl t-since-c23"><span> or <code><a href="http://en.cppreference.com/w/c/chrono/asctime"><span class="kw515">asctime</span></a><span class="br0">(</span>localtime_r<span class="br0">(</span>timer, <span class="sy3">&</span><span class="br0">(</span><span class="kw1">struct</span> <a href="http://en.cppreference.com/w/c/chrono/tm"><span class="kw522">tm</span></a><span class="br0">)</span><span class="br0">{</span><span class="nu0">0</span><span class="br0">}</span><span class="br0">)</span><span class="br0">)</span></code></span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>. <span class="t-rev-inl t-since-c23"><span>This function is deprecated and should not be used in new code.</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span> +</div> <div class="t-li1"> +<span class="t-li">2)</span> Same as <span class="t-v">(1)</span>, except that the function is equivalent to <code>asctime_s<span class="br0">(</span>buf, bufsz, localtime_s<span class="br0">(</span>timer, <span class="sy3">&</span><span class="br0">(</span><span class="kw1">struct</span> <a href="http://en.cppreference.com/w/c/chrono/tm"><span class="kw522">tm</span></a><span class="br0">)</span><span class="br0">{</span><span class="nu0">0</span><span class="br0">}</span><span class="br0">)</span><span class="br0">)</span></code>, 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>timer</code> is a null pointer </li> +<li> <code>bufsz</code> is less than <code>26</code> or greater than <code>RSIZE_MAX</code> </li> +</ul> </dd> +<dd>As with all bounds-checked functions, <code>ctime_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> <p>The resulting string has the following format:</p> +<div class="c source-c"><pre data-language="c">Www Mmm dd hh:mm:ss yyyy\n</pre></div> <ul> +<li> +<code>Www</code> - the day of the week (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> - the month (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> - the day of the month </li> +<li> +<code>hh</code> - hours </li> +<li> +<code>mm</code> - minutes </li> +<li> +<code>ss</code> - seconds </li> +<li> +<code>yyyy</code> - years </li> +</ul> <p>The function does not support localization.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> timer </td> <td> - </td> <td> pointer to a <code><a href="time_t" title="c/chrono/time t">time_t</a></code> object specifying the time to print </td> +</tr> <tr class="t-par"> <td> buf </td> <td> - </td> <td> pointer to the first element of a char array of size at least <code>bufsz</code> </td> +</tr> <tr class="t-par"> <td> bufsz </td> <td> - </td> <td> max number of bytes to output, typically the size of the buffer pointed to by <code>buf</code> </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. The string may be shared between <code><a href="asctime" title="c/chrono/asctime">asctime</a></code> and <code>ctime</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 (in which case the string representation of time has been written out to the array pointed to by <code>buf</code>), or non-zero on failure (in which case, the terminating null character is always written to <code>buf[0]</code> 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>ctime</code> returns a pointer to static data and is not thread-safe. In addition, it modifies the static <code><a href="tm" title="c/chrono/tm">tm</a></code> object which may be shared with <code><a href="gmtime" title="c/chrono/gmtime">gmtime</a></code> and <code><a href="localtime" title="c/chrono/localtime">localtime</a></code>. 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>ctime</code> and <code>ctime_s</code> because <code>strftime</code> is more flexible and locale-sensitive.</p> +<p>The behavior of <code>ctime</code> is undefined for the values of <code><a href="time_t" title="c/chrono/time t">time_t</a></code> that result in the string longer than 25 characters (e.g. year 10000).</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) +{ + time_t result = time(NULL); + printf("%s", ctime(&result)); + +#ifdef __STDC_LIB_EXT1__ + char str[26]; + ctime_s(str,sizeof str,&result); + printf("%s", str); +#endif +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">Tue May 26 21:51:03 2015 +Tue May 26 21:51:03 2015</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul> +<li> 7.27.3.2 The ctime function (p: 287-288) </li> +<li> K.3.8.2.2 The ctime_s function (p: 454) </li> +</ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.27.3.2 The ctime function (p: 393) </li> +<li> K.3.8.2.2 The ctime_s function (p: 626) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.23.3.2 The ctime function (p: 342) </li></ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 4.12.3.2 The ctime function </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="asctime" title="c/chrono/asctime"> <span class="t-lines"><span>asctime</span><span>asctime_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="tm" title="c/chrono/tm">tm</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/ctime" title="cpp/chrono/c/ctime">C++ documentation</a></span> for <code>ctime</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/ctime" class="_attribution-link">https://en.cppreference.com/w/c/chrono/ctime</a> + </p> +</div> |
