how to convert datetime to unix timestamp in c?

后端 未结 6 1256
刺人心
刺人心 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:02

    Here is a wired solution in c/pseudo code I just hacked together. Good luck!

    char * runner = NULL;
    char *string_orig = "YYYY-MM-DD HH:MM:SS";
    time_t time = 0;
    struct tm tmp;
    
    use strstr(string_orig, "-") and atoi foreach
    
      tmp->tm_year .. 
      tmp->tm_mon  .. 
      tmp->tm_mday ..  
      tmp->tm_hour  .. 
      tmp->tm_min  .. 
      tmp->tm_sec .. 
    
    with *runner as help
    
    time = mktime(&tm)
    

提交回复
热议问题