1MKTIME(P) POSIX Programmer's Manual MKTIME(P)
2
3
4
6 mktime - convert broken-down time into time since the Epoch
7
9 #include <time.h>
10
11 time_t mktime(struct tm *timeptr);
12
13
15 The mktime() function shall convert the broken-down time, expressed as
16 local time, in the structure pointed to by timeptr, into a time since
17 the Epoch value with the same encoding as that of the values returned
18 by time(). The original values of the tm_wday and tm_yday components of
19 the structure are ignored, and the original values of the other compo‐
20 nents are not restricted to the ranges described in <time.h>.
21
22 A positive or 0 value for tm_isdst shall cause mktime() to presume ini‐
23 tially that Daylight Savings Time, respectively, is or is not in effect
24 for the specified time. A negative value for tm_isdst shall cause
25 mktime() to attempt to determine whether Daylight Savings Time is in
26 effect for the specified time.
27
28 Local timezone information shall be set as though mktime() called
29 tzset().
30
31 The relationship between the tm structure (defined in the <time.h>
32 header) and the time in seconds since the Epoch is that the result
33 shall be as specified in the expression given in the definition of sec‐
34 onds since the Epoch (see the Base Definitions volume of
35 IEEE Std 1003.1-2001, Section 4.14, Seconds Since the Epoch) corrected
36 for timezone and any seasonal time adjustments, where the names in the
37 structure and in the expression correspond.
38
39 Upon successful completion, the values of the tm_wday and tm_yday com‐
40 ponents of the structure shall be set appropriately, and the other com‐
41 ponents are set to represent the specified time since the Epoch, but
42 with their values forced to the ranges indicated in the <time.h> entry;
43 the final value of tm_mday shall not be set until tm_mon and tm_year
44 are determined.
45
47 The mktime() function shall return the specified time since the Epoch
48 encoded as a value of type time_t. If the time since the Epoch cannot
49 be represented, the function shall return the value (time_t)-1.
50
52 No errors are defined.
53
54 The following sections are informative.
55
57 What day of the week is July 4, 2001?
58
59
60 #include <stdio.h>
61 #include <time.h>
62
63
64 struct tm time_str;
65
66
67 char daybuf[20];
68
69
70 int main(void)
71 {
72 time_str.tm_year = 2001 - 1900;
73 time_str.tm_mon = 7 - 1;
74 time_str.tm_mday = 4;
75 time_str.tm_hour = 0;
76 time_str.tm_min = 0;
77 time_str.tm_sec = 1;
78 time_str.tm_isdst = -1;
79 if (mktime(&time_str) == -1)
80 (void)puts("-unknown-");
81 else {
82 (void)strftime(daybuf, sizeof(daybuf), "%A", &time_str);
83 (void)puts(daybuf);
84 }
85 return 0;
86 }
87
89 None.
90
92 None.
93
95 None.
96
98 asctime() , clock() , ctime() , difftime() , gmtime() , localtime() ,
99 strftime() , strptime() , time() , utime() , the Base Definitions vol‐
100 ume of IEEE Std 1003.1-2001, <time.h>
101
103 Portions of this text are reprinted and reproduced in electronic form
104 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
105 -- Portable Operating System Interface (POSIX), The Open Group Base
106 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
107 Electrical and Electronics Engineers, Inc and The Open Group. In the
108 event of any discrepancy between this version and the original IEEE and
109 The Open Group Standard, the original IEEE and The Open Group Standard
110 is the referee document. The original Standard can be obtained online
111 at http://www.opengroup.org/unix/online.html .
112
113
114
115IEEE/The Open Group 2003 MKTIME(P)