'\"macro stdmacro
.if n .pH g3c.mktime @(#)mktime	40.15 of 10/27/89
.\" Copyright 1989 AT&T
.nr X
'\"macro stdmacro
.if n .pH g3c.mktime @(#)mktime	40.3 of 8/11/88
.nr X
.if \nX=0 .ds x} mktime 3C "C Programming Language Utilities" "\&"
.if \nX=1 .ds x} mktime 3C "C Programming Language Utilities"
.if \nX=2 .ds x} mktime 3C "" "\&"
.if \nX=3 .ds x} mktime "" "" "\&"
.TH \*(x}
.SH NAME
\f4mktime\f1 \- converts a \f4tm\f1 structure to a calendar time
.SH SYNOPSIS
\f4#include <time.h>\f1
.PP
\f4time_t mktime (struct tm \(**timeptr);\f1\f1
.SH DESCRIPTION
\f4mktime\fP converts the time represented by the \f4tm\f1 structure
pointed to by \f2timeptr\f1 into a calendar time 
(the number of seconds since 00:00:00 \s-1UTC\s+1, January 1, 1970).
.P
The \f4tm\f1 structure has the following format.
.RS
.PP
.nf
\f4struct	tm {	
	int	tm_sec;	/\(** seconds after the minute [0, 61]  \(**/
	int	tm_min;	/\(** minutes after the hour [0, 59] \(**/
	int	tm_hour;	/\(** hour since midnight [0, 23] \(**/
	int	tm_mday;	/\(** day of the month [1, 31] \(**/
	int	tm_mon;	/\(** months since January [0, 11] \(**/
	int	tm_year;	/\(** years since 1900 \(**/
	int	tm_wday;	/\(** days since Sunday [0, 6] \(**/
	int	tm_yday;	/\(** days since January 1 [0, 365] \(**/
	int	tm_isdst;	/\(** flag for daylight savings time \(**/
};\f1
.fi
.RE
.PP
In addition to computing the calendar time, \f4mktime\fP normalizes the
supplied \f4tm\f1 structure.
The original values of the \f4tm_wday\f1 and \f4tm_yday\f1
components of the structure are ignored, and the original values of the
other components are not restricted to the ranges indicated in the definition
of the structure.
On successful completion, the
values of the \f4tm_wday\f1 and \f4tm_yday\f1 components are set appropriately,
and the other components are set to represent the specified calendar time,
but with their values forced to be within the appropriate ranges.
The final value of \f4tm_mday\fP is not set until \f4tm_mon\fP and \f4tm_year\fP
are determined.
.PP
The original values of the components may be either greater than or less than
the specified range.
For example, a \f4tm_hour\f1 of \-1 means 1 hour before midnight,
\f4tm_mday\f1 of 0 means the day preceding the current month, and \f4tm_mon\f1
of \-2 means 2 months before January of \f4tm_year\f1.
.PP
If \f4tm_isdst\f1 is positive, the original values are assumed to be
in the alternate timezone.
If it turns out that the alternate timezone
is not valid for the computed calendar time, then the components are adjusted
to the main timezone.
Likewise, if
\f4tm_isdst\f1 is zero, the original values are assumed to be in the
main timezone and are converted to the alternate timezone if the main timezone
is not valid.
If \f4tm_isdst\f1 is negative, the correct timezone is
determined and the components are not adjusted.
.PP
Local timezone information is used as if \f4mktime\fP had called \f4tzset\fP.
.PP
\f4mktime\fP returns the specified calendar time.
If the calendar time cannot be represented, the function returns the value
(\f4time_t\f1)\-1.
.SH EXAMPLE
What day of the week is July 4, 2001?
.nf

	\f4#include <stdio.h>
	#include <time.h>

	static char \(**const wday[\|] = {
		"Sunday", "Monday", "Tuesday", "Wednesday",
		"Thursday", "Friday", "Saturday", "-unknown-"
	};
	struct tm time_str;
	/\(**...\(**/
	time_str.tm_year	= 2001 - 1900;
	time_str.tm_mon	= 7 - 1;
	time_str.tm_mday	= 4;
	time_str.tm_hour	= 0;
	time_str.tm_min	= 0;
	time_str.tm_sec		= 1;
	time_str.tm_isdst	= -1;
	if (mktime(&time_str)== -1)
	    time_str.tm_wday=7;
	printf("%s\\n", wday[time_str.tm_wday]);\f1

.fi
.SH "SEE ALSO"
\f4ctime\fP(3C), \f4getenv\fP(3C), \f4timezone\fP(4).
.SH NOTES
\f4tm_year\f1 of the \f4tm\f1 structure must be for year 1970 or later.
Calendar times before 00:00:00 \s-1UTC\s+1, January 1, 1970 or after 03:14:07 \s-1UTC\s+1, 
January 19, 2038 cannot be represented.
.\"	@(#)mktime.3c	
.Ee
