2.1.8.26 mktime


Description

Converts the supplied time structure to a time_t value.

Syntax

time_t mktime( TM * timeptr )

Parameters

[input] timeptr
Pointer to time structure

Return

mktime returns the specified calendar time encoded as a value of type time_t. If timeptr references a date before midnight, January 1, 1970, or if the calendar time cannot be represented, the function returns -1 cast to type time_t.

Examples

void mktime_Ex1()
{
	//set time is: 2009/4/2 9:15:30
	tm time = { 30, 15, 9, 2, 4, 109 };
	time_t clock = mktime(&time);
	printf( "Time in seconds since UTC 1/1/70:\t%ld\n", clock );
}

Remark

The mktime function converts the supplied time structure (possibly incomplete) pointed to by timeptr into a fully defined structure with normalized values and then converts it to a time_t calendar time value. For description of tm structure fields, see asctime. The converted time has the same encoding as the values returned by the time function. The original values of the tm_wday and tm_yday components of the timeptr structure are ignored, and the original values of the other components are not restricted to their normal ranges.


mktime handles dates in any time zone from midnight, January 1, 1970, to January 18, 19:14:07, 2038. If successful, mktime sets the values of tm_wday and tm_yday as appropriate and sets the other components to represent the specified calendar time, but with their values forced to the normal ranges; the final value of tm_mday is not set until tm_mon and tm_year are determined. When specifying a tm structure time, set the tm_isdst field to 0 to indicate that standard time is in effect, or to a value greater than 0 to indicate that daylight savings time is in effect, or to a value less than zero to have the C run-time library code compute whether standard time or daylight savings time is in effect. (The C run-time library assumes the United States's rules for implementing the calculation of Daylight Saving Time). tm_isdst is a required field. If not set, its value is undefined and the return value from mktime is unpredictable. If timeptr points to a tm structure returned by a previous call to asctime, gmtime, or localtime, the tm_isdst field contains the correct value.


Note that gmtime and localtime use a single statically allocated buffer for the conversion. If you supply this buffer to mktime, the previous contents are destroyed.

See Also

gmtime, localtime, time

Header to Include

origin.h

Reference