1MKTIME(3P)                 POSIX Programmer's Manual                MKTIME(3P)
2
3
4

PROLOG

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

NAME

12       mktime — convert broken-down time into time since the Epoch
13

SYNOPSIS

15       #include <time.h>
16
17       time_t mktime(struct tm *timeptr);
18

DESCRIPTION

20       The functionality described on this reference page is aligned with  the
21       ISO C  standard.  Any  conflict between the requirements described here
22       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
23       defers to the ISO C standard.
24
25       The  mktime() function shall convert the broken-down time, expressed as
26       local time, in the structure pointed to by timeptr, into a  time  since
27       the  Epoch  value with the same encoding as that of the values returned
28       by time().  The original values of the tm_wday and  tm_yday  components
29       of the structure shall be ignored, and the original values of the other
30       components shall not be restricted to the ranges described in <time.h>.
31
32       A positive or 0 value for tm_isdst shall cause mktime() to presume ini‐
33       tially that Daylight Savings Time, respectively, is or is not in effect
34       for the specified time. A  negative  value  for  tm_isdst  shall  cause
35       mktime()  to  attempt  to determine whether Daylight Savings Time is in
36       effect for the specified time.
37
38       Local timezone information shall  be  set  as  though  mktime()  called
39       tzset().
40
41       The  relationship  between  the  tm  structure (defined in the <time.h>
42       header) and the time in seconds since the  Epoch  is  that  the  result
43       shall be as specified in the expression given in the definition of sec‐
44       onds since the Epoch (see the Base Definitions volume of  POSIX.1‐2017,
45       Section  4.16,  Seconds Since the Epoch) corrected for timezone and any
46       seasonal time adjustments, where the names other than  tm_yday  in  the
47       structure  and in the expression correspond, and the tm_yday value used
48       in the expression is the day of the year from 0 to 365 inclusive,  cal‐
49       culated  from  the  other  tm  structure  members specified in <time.h>
50       (excluding tm_wday).
51
52       Upon successful completion, the values of the tm_wday and tm_yday  com‐
53       ponents of the structure shall be set appropriately, and the other com‐
54       ponents shall be set to represent the specified time since  the  Epoch,
55       but  with  their  values forced to the ranges indicated in the <time.h>
56       entry; the final value of tm_mday shall not be  set  until  tm_mon  and
57       tm_year are determined.
58

RETURN VALUE

60       The  mktime()  function shall return the specified time since the Epoch
61       encoded as a value of type time_t.  If the time since the Epoch  cannot
62       be  represented, the function shall return the value (time_t)-1 and set
63       errno to indicate the error.
64

ERRORS

66       The mktime() function shall fail if:
67
68       EOVERFLOW
69              The result cannot be represented.
70
71       The following sections are informative.
72

EXAMPLES

74       What day of the week is July 4, 2001?
75
76
77           #include <stdio.h>
78           #include <time.h>
79
80           struct tm time_str;
81
82           char daybuf[20];
83
84           int main(void)
85           {
86               time_str.tm_year = 2001 — 1900;
87               time_str.tm_mon = 7 — 1;
88               time_str.tm_mday = 4;
89               time_str.tm_hour = 0;
90               time_str.tm_min = 0;
91               time_str.tm_sec = 1;
92               time_str.tm_isdst = -1;
93               if (mktime(&time_str) == -1)
94                   (void)puts("-unknown-");
95               else {
96                   (void)strftime(daybuf, sizeof(daybuf), "%A", &time_str);
97                   (void)puts(daybuf);
98               }
99               return 0;
100           }
101

APPLICATION USAGE

103       None.
104

RATIONALE

106       None.
107

FUTURE DIRECTIONS

109       None.
110

SEE ALSO

112       asctime(), clock(), ctime(), difftime(), gmtime(),  localtime(),  strf‐
113       time(), strptime(), time(), tzset(), utime()
114
115       The  Base  Definitions  volume  of  POSIX.1‐2017, Section 4.16, Seconds
116       Since the Epoch, <time.h>
117
119       Portions of this text are reprinted and reproduced in  electronic  form
120       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
121       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
122       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
123       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
124       event of any discrepancy between this version and the original IEEE and
125       The Open Group Standard, the original IEEE and The Open Group  Standard
126       is  the  referee document. The original Standard can be obtained online
127       at http://www.opengroup.org/unix/online.html .
128
129       Any typographical or formatting errors that appear  in  this  page  are
130       most likely to have been introduced during the conversion of the source
131       files to man page format. To report such errors,  see  https://www.ker
132       nel.org/doc/man-pages/reporting_bugs.html .
133
134
135
136IEEE/The Open Group                  2017                           MKTIME(3P)
Impressum