Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/mktime.html
2024-02-19 00:21:47 -05:00

176 lines
6.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>mktime</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="mktime"></a> <a name="tag_03_376"></a><!-- mktime -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_376_01"></a>NAME</h4>
<blockquote>mktime - convert broken-down time into time since the Epoch</blockquote>
<h4><a name="tag_03_376_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/time.h.html">time.h</a>&gt;<br>
<br>
time_t mktime(struct tm *</tt><i>timeptr</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_376_03"></a>DESCRIPTION</h4>
<blockquote>
<div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
border="0"> The functionality described on this reference page is aligned with the ISO&nbsp;C standard. Any conflict between the
requirements described here and the ISO&nbsp;C standard is unintentional. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 defers to
the ISO&nbsp;C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div>
<p>The <i>mktime</i>() function shall convert the broken-down time, expressed as local time, in the structure pointed to by
<i>timeptr</i>, into a time since the Epoch value with the same encoding as that of the values returned by <a href=
"../functions/time.html"><i>time</i>()</a>. The original values of the <i>tm_wday</i> and <i>tm_yday</i> components of the
structure are ignored, and the original values of the other components are not restricted to the ranges described in <a href=
"../basedefs/time.h.html"><i>&lt;time.h&gt;</i></a>.</p>
<p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> A
positive or 0 value for <i>tm_isdst</i> shall cause <i>mktime</i>() to presume initially that Daylight Savings Time, respectively,
is or is not in effect for the specified time. A negative value for <i>tm_isdst</i> shall cause <i>mktime</i>() to attempt to
determine whether Daylight Savings Time is in effect for the specified time.</p>
<p>Local timezone information shall be set as though <i>mktime</i>() called <a href=
"../functions/tzset.html"><i>tzset</i>()</a>.</p>
<p>The relationship between the <b>tm</b> structure (defined in the <a href="../basedefs/time.h.html"><i>&lt;time.h&gt;</i></a>
header) and the time in seconds since the Epoch is that the result shall be as specified in the expression given in the definition
of seconds since the Epoch (see the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap04.html#tag_04_14">Section 4.14, Seconds Since the Epoch</a>) corrected for timezone and any seasonal time
adjustments, where the names in the structure and in the expression correspond. <img src="../images/opt-end.gif" alt="[Option End]"
border="0"></p>
<p>Upon successful completion, the values of the <i>tm_wday</i> and <i>tm_yday</i> components of the structure shall be set
appropriately, and the other components are set to represent the specified time since the Epoch, but with their values forced to
the ranges indicated in the <a href="../basedefs/time.h.html"><i>&lt;time.h&gt;</i></a> entry; the final value of <i>tm_mday</i>
shall not be set until <i>tm_mon</i> and <i>tm_year</i> are determined.</p>
</blockquote>
<h4><a name="tag_03_376_04"></a>RETURN VALUE</h4>
<blockquote>
<p>The <i>mktime</i>() function shall return the specified time since the Epoch encoded as a value of type <b>time_t</b>. If the
time since the Epoch cannot be represented, the function shall return the value (<b>time_t</b>)-1.</p>
</blockquote>
<h4><a name="tag_03_376_05"></a>ERRORS</h4>
<blockquote>
<p>No errors are defined.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_376_06"></a>EXAMPLES</h4>
<blockquote>
<p>What day of the week is July 4, 2001?</p>
<pre>
<tt>#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
<br>
struct tm time_str;
<br>
char daybuf[20];
<br>
int main(void)
{
time_str.tm_year = 2001 - 1900;
time_str.tm_mon = 7 - 1;
time_str.tm_mday = 4;
time_str.tm_hour = 0;
time_str.tm_min = 0;
time_str.tm_sec = 1;
time_str.tm_isdst = -1;
if (mktime(&amp;time_str) == -1)
(void)puts("-unknown-");
else {
(void)strftime(daybuf, sizeof(daybuf), "%A", &amp;time_str);
(void)puts(daybuf);
}
return 0;
}
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_376_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_376_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_376_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_376_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="asctime.html"><i>asctime</i>()</a> , <a href="clock.html"><i>clock</i>()</a> , <a href="ctime.html"><i>ctime</i>()</a>
, <a href="difftime.html"><i>difftime</i>()</a> , <a href="gmtime.html"><i>gmtime</i>()</a> , <a href=
"localtime.html"><i>localtime</i>()</a> , <a href="strftime.html"><i>strftime</i>()</a> , <a href=
"strptime.html"><i>strptime</i>()</a> , <a href="time.html"><i>time</i>()</a> , <a href="utime.html"><i>utime</i>()</a> , the Base
Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/time.h.html"><i>&lt;time.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_376_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 3. Included for alignment with the POSIX.1-1988 standard and the ANSI&nbsp;C standard.</p>
</blockquote>
<h4><a name="tag_03_376_12"></a>Issue 6</h4>
<blockquote>
<p>Extensions beyond the ISO&nbsp;C standard are marked.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>