How to convert a time into epoch time?

后端 未结 5 1478
感情败类
感情败类 2020-12-06 16:16

Say I have a specific instant in time where I know the hour, minute, day, second, month, year, etc; how can I convert this epoch time (seconds since 1970)?

I can\'t

5条回答
  •  庸人自扰
    2020-12-06 17:08

    mktime and memset is most portable for me:

    struct tm t;
    memset(&t, 0, sizeof(tm)); // Initalize to all 0's
    t.tm_year = 112; // This is year-1900, so 112 = 2012
    t.tm_mon = 8;
    t.tm_mday = 15;
    t.tm_hour = 21;
    t.tm_min = 54;
    t.tm_sec = 13;
    time_t time_since_epoch = mktime(&t);
    

提交回复
热议问题