summaryrefslogtreecommitdiff
path: root/devdocs/c/chrono%2Fgmtime.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/c/chrono%2Fgmtime.html')
-rw-r--r--devdocs/c/chrono%2Fgmtime.html71
1 files changed, 71 insertions, 0 deletions
diff --git a/devdocs/c/chrono%2Fgmtime.html b/devdocs/c/chrono%2Fgmtime.html
new file mode 100644
index 00000000..7aaae09c
--- /dev/null
+++ b/devdocs/c/chrono%2Fgmtime.html
@@ -0,0 +1,71 @@
+ <h1 id="firstHeading" class="firstHeading">gmtime, gmtime_r, gmtime_s</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;time.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td> <pre data-language="c">struct tm *gmtime ( const time_t *timer );</pre>
+</td> <td> (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">struct tm *gmtime_r( const time_t *timer, struct tm *buf );</pre>
+</td> <td> (2) </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">struct tm *gmtime_s( const time_t *restrict timer, struct tm *restrict buf );</pre>
+</td> <td> (3) </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 (a <code><a href="time_t" title="c/chrono/time t">time_t</a></code> value pointed to by <code>timer</code>) into calendar time, expressed in Coordinated Universal Time (UTC) in the <a href="tm" title="c/chrono/tm"><code>struct tm</code></a> format. The result is stored in static storage and a pointer to that static storage is returned.</div> <div class="t-li1">
+<span class="t-li">2)</span> Same as <span class="t-v">(1)</span>, except that the function uses user-provided storage <code>buf</code> for the result.</div> <div class="t-li1">
+<span class="t-li">3)</span> Same as <span class="t-v">(1)</span>, except that the function uses user-provided storage <code>buf</code> for the result and that 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>timer</code> or <code>buf</code> is a null pointer </li></ul> </dd>
+<dd>As with all bounds-checked functions, <code>gmtime_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>&lt;time.h&gt;</code></a>.</dd>
+</dl>
+</div> <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 to convert </td>
+</tr> <tr class="t-par"> <td> buf </td> <td> - </td> <td> pointer to a <code><span class="kw1">struct</span> <a href="http://en.cppreference.com/w/c/chrono/tm"><span class="kw522">tm</span></a></code> object to store the result </td>
+</tr>
+</table> <h3 id="Return_value"> Return value</h3> <div class="t-li1">
+<span class="t-li">1)</span> pointer to a static internal <code><a href="tm" title="c/chrono/tm">tm</a></code> object on success, or null pointer otherwise. The structure may be shared between <code>gmtime</code>, <code><a href="localtime" title="c/chrono/localtime">localtime</a></code>, and <code><a href="ctime" title="c/chrono/ctime">ctime</a></code> and may be overwritten on each invocation.</div> <div class="t-li1">
+<span class="t-li">2-3)</span> copy of the <code>buf</code> pointer, or null pointer on error (which may be a runtime constraint violation or a failure to convert the specified time to UTC)</div> <h3 id="Notes"> Notes</h3> <p><code>gmtime</code> may not be thread-safe.</p>
+<p>POSIX requires that <code>gmtime</code> and <code>gmtime_r</code> set <code><a href="../error/errno" title="c/error/errno">errno</a></code> to <code><a href="../error/errno_macros" title="c/error/errno macros">EOVERFLOW</a></code> if they fail because the argument is too large.</p>
+<p>The implementation of <code>gmtime_s</code> in <a rel="nofollow" class="external text" href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/gmtime-s-gmtime32-s-gmtime64-s?view=vs-2019">Microsoft CRT</a> is incompatible with the C standard since it has reversed parameter order.</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
+#define _XOPEN_SOURCE // for putenv
+#include &lt;time.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt; // for putenv
+
+int main(void)
+{
+ time_t t = time(NULL);
+ printf("UTC: %s", asctime(gmtime(&amp;t)));
+ printf("local: %s", asctime(localtime(&amp;t)));
+ // POSIX-specific
+ putenv("TZ=Asia/Singapore");
+ printf("Singapore: %s", asctime(localtime(&amp;t)));
+
+#ifdef __STDC_LIB_EXT1__
+ struct tm buf;
+ char str[26];
+ asctime_s(str,sizeof str,gmtime_s(&amp;t, &amp;buf));
+ printf("UTC: %s", str);
+ asctime_s(str,sizeof str,localtime_s(&amp;t, &amp;buf));
+ printf("local: %s", str);
+#endif
+}</pre></div> <p>Possible output:</p>
+<div class="text source-text"><pre data-language="c">UTC: Fri Sep 15 14:22:05 2017
+local: Fri Sep 15 14:22:05 2017
+Singapore: Fri Sep 15 22:22:05 2017
+UTC: Fri Sep 15 14:22:05 2017
+local: Fri Sep 15 14:22:05 2017</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul>
+<li> 7.27.3.3 The gmtime function (p: 288) </li>
+<li> K.3.8.2.3 The gmtime_s function (p: 454-455) </li>
+</ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul>
+<li> 7.27.3.3 The gmtime function (p: 393-394) </li>
+<li> K.3.8.2.3 The gmtime_s function (p: 626-627) </li>
+</ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 7.23.3.3 The gmtime function (p: 343) </li></ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 4.12.3.3 The gmtime function </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="localtime" title="c/chrono/localtime"> <span class="t-lines"><span>localtime</span><span>localtime_r</span><span>localtime_s</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> converts time since epoch to calendar time expressed as local time <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/gmtime" title="cpp/chrono/c/gmtime">C++ documentation</a></span> for <code>gmtime</code> </td>
+</tr> </table> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
+ <a href="https://en.cppreference.com/w/c/chrono/gmtime" class="_attribution-link">https://en.cppreference.com/w/c/chrono/gmtime</a>
+ </p>
+</div>