summaryrefslogtreecommitdiff
path: root/devdocs/c/chrono%2Ftime_t.html
blob: d6e589de9c24b733382e4cab3858be3a137dad0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    <h1 id="firstHeading" class="firstHeading">time_t</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 class="t-dcl-nopad"> <pre data-language="c">typedef /* unspecified */ time_t;</pre>
</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr>  </table> <p>Real arithmetic type capable of representing times.</p>
<p>Although not defined by the C standard, this is almost always an integral value holding the number of seconds (not counting leap seconds) since 00:00, Jan 1 1970 UTC, corresponding to <a href="https://en.wikipedia.org/wiki/Unix_time" class="extiw" title="enwiki:Unix time"> POSIX time</a>.</p>
<h3 id="Notes"> Notes</h3> <p>The standard uses the term <i>calendar time</i> when referring to a value of type <code>time_t</code>.</p>
<h3 id="Example"> Example</h3> <div class="t-example">
<p>Show the start of the epoch.</p>
<div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
#include &lt;stdint.h&gt;
 
int main(void)
{
    time_t epoch = 0;
    printf("%jd seconds since the epoch began\n", (intmax_t)epoch);
    printf("%s", asctime(gmtime(&amp;epoch)));
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">0 seconds since the epoch began
Thu Jan  1 00:00:00 1970</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.27.1/3 Components of time (p: 284) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.27.1/3 Components of time (p: 388) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.23.1/3 Components of time (p: 338) </li></ul>
<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
<ul><li> 4.12.1 Components of time </li></ul>
</ul>               <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="time" title="c/chrono/time"> <span class="t-lines"><span>time</span></span></a></div> </td> <td> returns the current calendar time of the system as time since epoch <br> <span class="t-mark">(function)</span>  </td>
</tr> <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> <div><a href="gmtime" title="c/chrono/gmtime"> <span class="t-lines"><span>gmtime</span><span>gmtime_r</span><span>gmtime_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 Coordinated Universal Time (UTC) <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/time_t" title="cpp/chrono/c/time t">C++ documentation</a></span> for <code>time_t</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/time_t" class="_attribution-link">https://en.cppreference.com/w/c/chrono/time_t</a>
  </p>
</div>