Format
#include <time.h> time_t mktime(struct tm *time);
Language Level: ANSI, POSIX, XPG4
mktime converts local time, stored as a tm structure pointed to
by time, into a time_t value suitable for use with
other time functions. The values of some structure elements
pointed to by time are not restricted to the ranges shown for gmtime -- Convert Time .
The values of tm_wday and tm_yday passed to mktime are ignored and are assigned their correct values on return, and the other components [of the tm structure] are set to represent the specified calendar time, but with their values forced to the ranges indicated above.
Note:
Calendar time is the number of seconds that have elapsed
since EPOCH, which is 00:00:00, January 1, 1970 Universal
Coordinate Time (UTC).
On both OS/2 and Windows, the time and date functions begin at 00:00:00 Universal Coordinate Time, January 1, 1970, and do not have an upper limit.
Return Value
mktime returns the calendar time having type time_t. The
value (time_t)(-1) is returned if the calendar time cannot be
represented.
Example
This example prints the day of the week that is 40 days
and 16 hours from the current date.
#include <stdio.h> #include <time.h>
int main(void)
{
time_t t1;
struct tm *t2;
char buffer[50];
t1 = time(NULL);
t2 = localtime(&t1);
t2->tm_mday += 40;
t2->tm_hour += 16;
mktime(t2);
strftime(buffer, sizeof(buffer), "%A", t2);
printf("40 days and 16 hours from now, it will be a %s \n", buffer);
return 0;
/*******************************************************************
The output should be similar to:
40 days and 16 hours from now, it will be a Sunday *******************************************************************/ }
![]()
asctime -- Convert Time to Character
String
ctime -- Convert Time to Character String
gmtime -- Convert Time
localtime -- Convert Time
time -- Determine Current Time
<time.h>