#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm str_time;
time_t time_of_day;
struct tm str_time1;
time_t time_of_day1;
str_time.tm_year = 2012; //-1900;
str_time.tm_mon = 6;
str_time.tm_mday = 5;
str_time.tm_hour = 10;
str_time.tm_min = 3;
str_time.tm_sec = 5;
str_time.tm_isdst = 0;
str_time1.tm_year = 2017-1900;
str_time1.tm_mon = 1;
str_time1.tm_mday = 1;
str_time1.tm_hour = 1;
str_time1.tm_min = 1;
str_time1.tm_sec = 1;
str_time1.tm_isdst = 0;
time_of_day = mktime(&str_time);
printf(ctime(&time_of_day));
time_of_day1 = mktime(&str_time1);
printf(ctime(&time_of_day1));
int f = mktime(&str_time);
printf("\n mktime: %d \n", f);
int g = mktime(&str_time1);
printf("\n mktime: %d \n", g);
return 0;
}
**********************************************************************
output:
**********************************************************************
#include <stdio.h>
int main(void)
{
struct tm str_time;
time_t time_of_day;
struct tm str_time1;
time_t time_of_day1;
str_time.tm_year = 2012; //-1900;
str_time.tm_mon = 6;
str_time.tm_mday = 5;
str_time.tm_hour = 10;
str_time.tm_min = 3;
str_time.tm_sec = 5;
str_time.tm_isdst = 0;
str_time1.tm_year = 2017-1900;
str_time1.tm_mon = 1;
str_time1.tm_mday = 1;
str_time1.tm_hour = 1;
str_time1.tm_min = 1;
str_time1.tm_sec = 1;
str_time1.tm_isdst = 0;
time_of_day = mktime(&str_time);
printf(ctime(&time_of_day));
time_of_day1 = mktime(&str_time1);
printf(ctime(&time_of_day1));
int f = mktime(&str_time);
printf("\n mktime: %d \n", f);
int g = mktime(&str_time1);
printf("\n mktime: %d \n", g);
return 0;
}
**********************************************************************
output:
**********************************************************************
sh-4.2$ main
Thu Jul 5 10:03:05 2012
Wed Feb 1 01:01:01 2017
mktime: 1341482585
mktime: 1485910861