how to convert datetime to unix timestamp in c?

后端 未结 6 1245
刺人心
刺人心 2020-11-29 06:22

the scenario is: I get datetime in format \"YYYY-MM-DD HH:MM:SS\" with libexif. To minimize the saving cost, I wanna convert the datetime to unix timestamp or alike which on

6条回答
  •  隐瞒了意图╮
    2020-11-29 07:19

    What about sscanf?

    struct tm tmVar;
    char *strVar = "YYYY-MM-DD HH:MM:SS";
    time_t timeVar;
    if(sscanf(strVar, "%d-%d-%d %d:%d:%d", &tm.tm_year, /* the other fields */)==6)
        timeVar = mktime(&tmVar);
    else
        // bad format
    

提交回复
热议问题