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%2Fmktime.html | |
new repository
Diffstat (limited to 'devdocs/c/chrono%2Fmktime.html')
| -rw-r--r-- | devdocs/c/chrono%2Fmktime.html | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/devdocs/c/chrono%2Fmktime.html b/devdocs/c/chrono%2Fmktime.html new file mode 100644 index 00000000..d4a34bc9 --- /dev/null +++ b/devdocs/c/chrono%2Fmktime.html @@ -0,0 +1,46 @@ + <h1 id="firstHeading" class="firstHeading">mktime</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"> <td class="t-dcl-nopad"> <pre data-language="c">time_t mktime( struct tm *arg );</pre> +</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> </table> <p>Renormalizes local calendar time expressed as a <code><a href="tm" title="c/chrono/tm">struct tm</a></code> object and also converts it to time since epoch as a <code><a href="time_t" title="c/chrono/time t">time_t</a></code> object. <code>arg->tm_wday</code> and <code>arg->tm_yday</code> are ignored. The values in <code>arg</code> are not checked for being out of range.</p> +<p>A negative value of <code>arg->tm_isdst</code> causes <code>mktime</code> to attempt to determine if Daylight Saving Time was in effect in the specified time.</p> +<p>If the conversion to <code>time_t</code> is successful, the <code>arg</code> object is modified. All fields of <code>arg</code> are updated to fit their proper ranges. <code>arg->tm_wday</code> and <code>arg->tm_yday</code> are recalculated using information available in other fields.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> pointer to a <code><a href="tm" title="c/chrono/tm">tm</a></code> object specifying local calendar time to convert </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>time since epoch as a <code><a href="time_t" title="c/chrono/time t">time_t</a></code> object on success, or <code>-1</code> if <code>arg</code> cannot be represented as a <code><a href="time_t" title="c/chrono/time t">time_t</a></code> object (POSIX also requires <code>EOVERFLOW</code> to be stored in <code><a href="../error/errno" title="c/error/errno">errno</a></code> in this case).</p> +<h3 id="Notes"> Notes</h3> <p>If the <code><span class="kw1">struct</span> <a href="http://en.cppreference.com/w/c/chrono/tm"><span class="kw522">tm</span></a></code> object was obtained from POSIX <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html"><code>strptime</code></a> or equivalent function, the value of <code>tm_isdst</code> is indeterminate, and needs to be set explicitly before calling <code>mktime</code>.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#define _POSIX_C_SOURCE 200112L // for setenv on gcc +#include <stdlib.h> +#include <stdio.h> +#include <time.h> + +int main(void) +{ + setenv("TZ", "/usr/share/zoneinfo/America/New_York", 1); // POSIX-specific + + struct tm tm = *localtime(&(time_t){time(NULL)}); + printf("Today is %s", asctime(&tm)); + printf("(DST is %s)\n", tm.tm_isdst ? "in effect" : "not in effect"); + tm.tm_mon -= 100; // tm_mon is now outside its normal range + mktime(&tm); // tm_isdst is not set to -1; today's DST status is used + printf("100 months ago was %s", asctime(&tm)); + printf("(DST was %s)\n", tm.tm_isdst ? "in effect" : "not in effect"); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">Today is Fri Apr 22 11:53:36 2016 +(DST is in effect) +100 months ago was Sat Dec 22 10:53:36 2007 +(DST was not in effect)</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul><li> 7.27.2.3 The mktime function (p: 285-286) </li></ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.27.2.3 The mktime function (p: 390-391) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.23.2.3 The mktime function (p: 340-341) </li></ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 4.12.2.3 The mktime 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/mktime" title="cpp/chrono/c/mktime">C++ documentation</a></span> for <code>mktime</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/mktime" class="_attribution-link">https://en.cppreference.com/w/c/chrono/mktime</a> + </p> +</div> |
