timegm cross platform

前端 未结 5 995
忘了有多久
忘了有多久 2020-12-06 16:55

I\'m using Visual Studio c++ Compiler ( 2010 ), but the library has different implementation of ANSI C and POSIX libraries function.

What is the difference betw

5条回答
  •  佛祖请我去吃肉
    2020-12-06 17:26

    My implementation of timegm is working on windows.

    time_t timegm(struct tm * a_tm)
    {
        time_t ltime = mktime(a_tm);
        struct tm tm_val;
        gmtime_s(&tm_val, <ime);
        int offset = (tm_val.tm_hour - a_tm->tm_hour);
        if (offset > 12)
        {
            offset = 24 - offset;
        }
        time_t utc = mktime(a_tm) - offset * 3600;
        return utc;
    }
    

    Should be fine.

提交回复
热议问题