time_t mktime(struct tm *tmp)
1.0、参考
1.1、此函数的作用

struct tm表示的时间转换为time_t表示的时间。

1.2、参数说明

struct tm的定义:

struct tm {
    int tm_sec;   /* seconds [0,60] */
    int tm_min;   /* minutes [0,59] */
    int tm_hour;  /* hours   [0,23]*/
    int tm_mday;  /* day of the month [1,31] */
    int tm_mon;   /* month   [0,11] */
    int tm_year;  /* year since 1900 */
    int tm_wday;  /* day of the week [0,6] (Sunday =0) */
    int tm_yday;  /* day in the year [0,365] */
    int tm_isdst; /* daylight saving time */
};
1.3、返回值说明

time_t的定义:

typedef long int __time_t;
typedef __time_t time_t;

time_t表示从1970-01-01 00:00:00,到某个时间点,所经过的数, 它是相对时间。

time_t是一个有符号数,也就是它也可以是负数,表示1970-01-01 00:00:00之前的时间。

1.4、使用示例
#include <stdio.h>
#include <time.h>

int main() {
    struct tm tms = {.tm_year = 2019 - 1900, .tm_mon = 3 - 1, .tm_mday = 18};
    time_t tt = mktime(&tms);
    printf("tt = %ld\n", tt2);
    return 0;
}

使用cc命令编译 ⤵︎

cc -o test_time test.c

运行结果如下 ⤵︎

tt = 1552838400