1MKTIME(3P) POSIX Programmer's Manual MKTIME(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 mktime — convert broken-down time into time since the Epoch
14
16 #include <time.h>
17
18 time_t mktime(struct tm *timeptr);
19
21 The functionality described on this reference page is aligned with the
22 ISO C standard. Any conflict between the requirements described here
23 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
24 defers to the ISO C standard.
25
26 The mktime() function shall convert the broken-down time, expressed as
27 local time, in the structure pointed to by timeptr, into a time since
28 the Epoch value with the same encoding as that of the values returned
29 by time(). The original values of the tm_wday and tm_yday components
30 of the structure are ignored, and the original values of the other com‐
31 ponents are not restricted to the ranges described in <time.h>.
32
33 A positive or 0 value for tm_isdst shall cause mktime() to presume ini‐
34 tially that Daylight Savings Time, respectively, is or is not in effect
35 for the specified time. A negative value for tm_isdst shall cause
36 mktime() to attempt to determine whether Daylight Savings Time is in
37 effect for the specified time.
38
39 Local timezone information shall be set as though mktime() called
40 tzset().
41
42 The relationship between the tm structure (defined in the <time.h>
43 header) and the time in seconds since the Epoch is that the result
44 shall be as specified in the expression given in the definition of sec‐
45 onds since the Epoch (see the Base Definitions volume of POSIX.1‐2008,
46 Section 4.15, Seconds Since the Epoch) corrected for timezone and any
47 seasonal time adjustments, where the names in the structure and in the
48 expression correspond.
49
50 Upon successful completion, the values of the tm_wday and tm_yday com‐
51 ponents of the structure shall be set appropriately, and the other com‐
52 ponents are set to represent the specified time since the Epoch, but
53 with their values forced to the ranges indicated in the <time.h> entry;
54 the final value of tm_mday shall not be set until tm_mon and tm_year
55 are determined.
56
58 The mktime() function shall return the specified time since the Epoch
59 encoded as a value of type time_t. If the time since the Epoch cannot
60 be represented, the function shall return the value (time_t)−1 and set
61 errno to indicate the error.
62
64 The mktime() function shall fail if:
65
66 EOVERFLOW
67 The result cannot be represented.
68
69 The following sections are informative.
70
72 What day of the week is July 4, 2001?
73
74 #include <stdio.h>
75 #include <time.h>
76
77 struct tm time_str;
78
79 char daybuf[20];
80
81 int main(void)
82 {
83 time_str.tm_year = 2001 — 1900;
84 time_str.tm_mon = 7 — 1;
85 time_str.tm_mday = 4;
86 time_str.tm_hour = 0;
87 time_str.tm_min = 0;
88 time_str.tm_sec = 1;
89 time_str.tm_isdst = −1;
90 if (mktime(&time_str) == -1)
91 (void)puts("-unknown-");
92 else {
93 (void)strftime(daybuf, sizeof(daybuf), "%A", &time_str);
94 (void)puts(daybuf);
95 }
96 return 0;
97 }
98
100 None.
101
103 None.
104
106 None.
107
109 asctime(), clock(), ctime(), difftime(), gmtime(), localtime(), strf‐
110 time(), strptime(), time(), tzset(), utime()
111
112 The Base Definitions volume of POSIX.1‐2008, Section 4.15, Seconds
113 Since the Epoch, <time.h>
114
116 Portions of this text are reprinted and reproduced in electronic form
117 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
118 -- Portable Operating System Interface (POSIX), The Open Group Base
119 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
120 cal and Electronics Engineers, Inc and The Open Group. (This is
121 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
122 event of any discrepancy between this version and the original IEEE and
123 The Open Group Standard, the original IEEE and The Open Group Standard
124 is the referee document. The original Standard can be obtained online
125 at http://www.unix.org/online.html .
126
127 Any typographical or formatting errors that appear in this page are
128 most likely to have been introduced during the conversion of the source
129 files to man page format. To report such errors, see https://www.ker‐
130 nel.org/doc/man-pages/reporting_bugs.html .
131
132
133
134IEEE/The Open Group 2013 MKTIME(3P)