2 .\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 2016 Joyent, Inc.
4 .\" Copyright 1989 AT&T
5 .\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7 .\" http://www.opengroup.org/bookstore/.
8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\" This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH MKTIME 3C "Mar 14, 2016"
15 mktime, timegm \- convert a tm structure to a calendar time
21 \fBtime_t\fR \fBmktime\fR(\fBstruct tm *\fR\fItimeptr\fR);
25 \fBtime_t\fR \fBtimegm\fR(\fBstruct tm *\fR\fItimeptr\fR);
30 The \fBmktime()\fR function converts the time represented by the \fBtm\fR
31 structure pointed to by \fItimeptr\fR into a calendar time (the number of
32 seconds since 00:00:00 UTC, January 1, 1970).
35 The \fBtm\fR structure contains the following members:
39 int tm_sec; /* seconds after the minute [0, 60] */
40 int tm_min; /* minutes after the hour [0, 59] */
41 int tm_hour; /* hour since midnight [0, 23] */
42 int tm_mday; /* day of the month [1, 31] */
43 int tm_mon; /* months since January [0, 11] */
44 int tm_year; /* years since 1900 */
45 int tm_wday; /* days since Sunday [0, 6] */
46 int tm_yday; /* days since January 1 [0, 365] */
47 int tm_isdst; /* flag for daylight savings time */
53 In addition to computing the calendar time, \fBmktime()\fR normalizes the
54 supplied \fBtm\fR structure. The original values of the \fBtm_wday\fR and
55 \fBtm_yday\fR components of the structure are ignored, and the original values
56 of the other components are not restricted to the ranges indicated in the
57 definition of the structure. On successful completion, the values of the
58 \fBtm_wday\fR and \fBtm_yday\fR components are set appropriately, and the other
59 components are set to represent the specified calendar time, but with their
60 values forced to be within the appropriate ranges. The final value of
61 \fBtm_mday\fR is not set until \fBtm_mon\fR and \fBtm_year\fR are determined.
64 The \fBtm_year\fR member must be for year 1901 or later. Calendar times before
65 20:45:52 UTC, December 13, 1901 or after 03:14:07 UTC, January 19, 2038 cannot
66 be represented. Portable applications should not try to create dates before
67 00:00:00 UTC, January 1, 1970 or after 00:00:00 UTC, January 1, 2038.
70 The original values of the components may be either greater than or less than
71 the specified range. For example, a \fBtm_hour\fR of \(mi1 means 1 hour before
72 midnight, \fBtm_mday\fR of 0 means the day preceding the current month, and
73 \fBtm_mon\fR of \(mi2 means 2 months before January of \fBtm_year\fR.
76 If \fBtm_isdst\fR is positive, the original values are assumed to be in the
77 alternate timezone. If it turns out that the alternate timezone is not valid
78 for the computed calendar time, then the components are adjusted to the main
79 timezone. Likewise, if \fBtm_isdst\fR is zero, the original values are assumed
80 to be in the main timezone and are converted to the alternate timezone if the
81 main timezone is not valid. If \fBtm_isdst\fR is negative, \fBmktime()\fR
82 attempts to determine whether the alternate timezone is in effect for the
86 Local timezone information is used as if \fBmktime()\fR had called
87 \fBtzset()\fR. See \fBctime\fR(3C).
90 The \fBtimegm()\fR function is identical to the \fBmktime()\fR function,
91 except that the \fBtimegm()\fR function ignores both the current time
92 zone and the \fBtm_isdst\fR member and operates as though the time zone
96 If the calendar time can be represented in an object of type
97 \fBtime_t\fR, the \fBmktime()\fR and \fBtimegm()\fR functions return the
98 specified calendar time without changing \fBerrno\fR. If the calendar
99 time cannot be represented, the function returns the value
100 (\fBtime_t\fR)\(mi1 and sets \fBerrno\fR to indicate the error.
103 The \fBmktime()\fR and \fBtimegm()\fR functions will fail if:
107 \fB\fBEOVERFLOW\fR\fR
110 The date represented by the input \fBtm\fR struct cannot be represented in a
111 \fBtime_t\fR. Note that the \fBerrno\fR setting may change if future revisions
112 to the standards specify a different value.
117 The \fBmktime()\fR and \fBtimegm()\fR functions are MT-Safe in
118 multithreaded applications, as long as no user-defined function directly
119 modifies one of the following variables: \fBtimezone\fR, \fBaltzone\fR,
120 \fBdaylight\fR, and \fBtzname\fR. See \fBctime\fR(3C).
123 Note that \(mi1 can be a valid return value for the time that is one
124 second before the Epoch. The user should clear \fBerrno\fR before
125 calling \fBmktime()\fR and \fBtimegm()\fR. If \fBmktime()\fR or
126 \fBtimegm()\fR then returns \(mi1, the user should check \fBerrno\fR to
127 determine whether or not an error actually occurred.
130 The \fBmktime()\fR and \fBtimegm()\fR functions assume Gregorian dates.
131 Times before the adoption of the Gregorian calendar will not match
135 \fBExample 1 \fRSample code using \fBmktime()\fR.
138 What day of the week is July 4, 2001?
145 static char *const wday[\|] = {
146 "Sunday", "Monday", "Tuesday", "Wednesday",
147 "Thursday", "Friday", "Saturday", "-unknown-"
151 time_str.tm_year = 2001 - 1900;
152 time_str.tm_mon = 7 - 1;
153 time_str.tm_mday = 4;
154 time_str.tm_hour = 0;
157 time_str.tm_isdst = \(mi1;
158 if (mktime(&time_str)== \(mi1)
160 printf("%s\en", wday[time_str.tm_wday]);
166 The \fBzoneinfo\fR timezone data files do not transition past Tue Jan 19
167 03:14:07 2038 UTC. Therefore for 64-bit applications using \fBzoneinfo\fR
168 timezones, calculations beyond this date may not use the correct offset from
169 standard time, and could return incorrect values. This affects the 64-bit
170 versions of \fBmktime()\fR and \fBtimegm()\fR.
173 See \fBattributes\fR(5) for descriptions of the following attributes:
181 ATTRIBUTE TYPE ATTRIBUTE VALUE
183 Interface Stability Standard
185 MT-Level MT-Safe with exceptions
190 \fBctime\fR(3C), \fBgetenv\fR(3C), \fBTIMEZONE\fR(4), \fBattributes\fR(5),