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
19

DESCRIPTION

21       The mktime() function shall convert the broken-down time, expressed  as
22       local  time,  in the structure pointed to by timeptr, into a time since
23       the Epoch value with the same encoding as that of the  values  returned
24       by time(). The original values of the tm_wday and tm_yday components of
25       the structure are ignored, and the original values of the other  compo‐
26       nents are not restricted to the ranges described in <time.h>.
27
28       A positive or 0 value for tm_isdst shall cause mktime() to presume ini‐
29       tially that Daylight Savings Time, respectively, is or is not in effect
30       for  the  specified  time.  A  negative  value for tm_isdst shall cause
31       mktime() to attempt to determine whether Daylight Savings  Time  is  in
32       effect for the specified time.
33
34       Local  timezone  information  shall  be  set  as though mktime() called
35       tzset().
36
37       The relationship between the tm  structure  (defined  in  the  <time.h>
38       header)  and  the  time  in  seconds since the Epoch is that the result
39       shall be as specified in the expression given in the definition of sec‐
40       onds   since   the   Epoch   (see   the   Base  Definitions  volume  of
41       IEEE Std 1003.1-2001, Section 4.14, Seconds Since the Epoch)  corrected
42       for  timezone and any seasonal time adjustments, where the names in the
43       structure and in the expression correspond.
44
45       Upon successful completion, the values of the tm_wday and tm_yday  com‐
46       ponents of the structure shall be set appropriately, and the other com‐
47       ponents are set to represent the specified time since  the  Epoch,  but
48       with their values forced to the ranges indicated in the <time.h> entry;
49       the final value of tm_mday shall not be set until  tm_mon  and  tm_year
50       are determined.
51

RETURN VALUE

53       The  mktime()  function shall return the specified time since the Epoch
54       encoded as a value of type time_t. If the time since the  Epoch  cannot
55       be represented, the function shall return the value (time_t)-1.
56

ERRORS

58       No errors are defined.
59
60       The following sections are informative.
61

EXAMPLES

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

APPLICATION USAGE

95       None.
96

RATIONALE

98       None.
99

FUTURE DIRECTIONS

101       None.
102

SEE ALSO

104       asctime(),  clock(),  ctime(), difftime(), gmtime(), localtime(), strf‐
105       time(), strptime(), time(), utime(), the  Base  Definitions  volume  of
106       IEEE Std 1003.1-2001, <time.h>
107
109       Portions  of  this text are reprinted and reproduced in electronic form
110       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
111       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
112       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
113       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
114       event of any discrepancy between this version and the original IEEE and
115       The  Open Group Standard, the original IEEE and The Open Group Standard
116       is the referee document. The original Standard can be  obtained  online
117       at http://www.opengroup.org/unix/online.html .
118
119
120
121IEEE/The Open Group                  2003                           MKTIME(3P)
Impressum