C Reference function mktime()

Usage of mktime():

time_t mktime ( struct tm * ptr_time );


The pointer ptr_time points to a tm structure that contains a calendar time, which in turn is broken down into its components.

Return Value:

A time_t value corresponding to the calendar time passed as argument.
If an error occurs then the function mktime() returns a -1 value.


The contents of the tm structure is interpret by the mktime function as a calendar time expressed in local time.
This calendar time is then used to change the values of the members of the ptr_time. The result will be returned as an object of the type time_t.

The original values of the members tm_wday and tm_yday of timeptr are ignored.

Note: the ranges of values for the rest of its members are not restricted to their normal values.

The object pointed by ptr_time is modified, setting the tm_wday and tm_yday to their appropriate values.
It then modifies the other members, if necessary, to values within the normal range representing the specified time.

Source code example of mktime():

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

	int main(void)
		struct tm time_info;
		time_t time_raw_format;

		time_info.tm_year = 2008-1900;
		time_info.tm_mon = 0;
		time_info.tm_mday = 1;
		time_info.tm_hour = 0;
		time_info.tm_min = 0;
		time_info.tm_sec = 1;
		time_info.tm_isdst = 0;

		time_raw_format = mktime(&time_info);
		return 0;

Output example of the program above:

	Tue Jan  1 00:00:01 2008
This entry was posted in C Reference time.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

Comments are closed.