none
gmtime API is returning different time in WEC7 and WINDOWS7 platforms RRS feed

  • Question

  • Hi all,

    I am working on WEC7 application developement.I want to convert current system time(time_t time value) to a tm structure in WEC7.In Windows 7 we can do it directly by calling gmtime API.

    But in WEC7 i found wcecompat-master library in which gmtime API implementation is as below

    struct tm* gmtime(const time_t* clock)
    {
    FILETIME ftUtc;
    SYSTEMTIME stUtc;

    if (clock == NULL)
    return NULL;

    // convert time_t to FILETIME
    UnixTimeToFileTime(*clock,&ftUtc);

    // convert to SYSTEMTIME
    if (!FileTimeToSystemTime(&ftUtc, &stUtc))
    return NULL;

    stUtc.wMilliseconds = 500;
    // fill return structure
    st_tm.tm_sec = stUtc.wSecond;
    st_tm.tm_min = stUtc.wMinute;
    st_tm.tm_hour = stUtc.wHour;
    st_tm.tm_mday = stUtc.wDay;
    st_tm.tm_mon = stUtc.wMonth;
    st_tm.tm_year = stUtc.wYear;
    st_tm.tm_wday = stUtc.wDayOfWeek;
    st_tm.tm_yday = dayOfYear(stUtc.wYear, stUtc.wMonth-1, stUtc.wDay);
    st_tm.tm_isdst = 0;

    return &st_tm;

    }

    void UnixTimeToFileTime(time_t t, LPFILETIME pft)
    {
    // Note that LONGLONG is a 64-bit value
    LONGLONG ll;

    ll = Int32x32To64(t, 10000000) + 116444736000000000;
    pft->dwLowDateTime = (DWORD)ll;
        pft->dwHighDateTime = (DWORD)(ll >> 32);
    }

    When gmtime API is called in WEC7 it is returning year+1900 and month+1 compared to Windows7.

    example:When current system time of 1545258796 seconds is sent to gmtime API ,returning result for both are as below

    --Windows7 returned time is 0118:11:19:22:33:16

    --WEC7 returned time is 2018:12:19:22:33:16

    Can Anyone suggest me the reason and fix for this WEC7 gmtime implementation ?

    Wednesday, December 19, 2018 1:25 PM