Home Ask Login Register

Developers Planet

Your answer is one click away!

Srikanth 2 weeks ago

How to convert milli seconds time to FILETIME in c++

I have a time in secs (ex:1505306792).

How to convert this into FILETIME?

Here is the code i have tried

    INT64 timer64 = 1505306792;

    timer64 = timer64 *1000 *10000;

    ULONGLONG xx = timer64;

    FILETIME fileTime;

    uliTime.QuadPart = xx;
    fileTime.dwHighDateTime = uliTime.HighPart;
    fileTime.dwLowDateTime = uliTime.LowPart;

This result FILETIME is coming as 1648-09-13 15:34:00

I am expecting this date to be 2017-09-13 12:46:31 . I am getting the same when using online converters.

Any idea how to solve this?

I have seen some answers using boost, but it is available in my project.


Roman R. 2 weeks ago

It's about adding 116444736000000000, see How To Convert a UNIX time_t to a Win32 FILETIME or SYSTEMTIME:

   #include <winbase.h>
   #include <winnt.h>
   #include <time.h>

   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 = ll >> 32;

Post Status

Asked in 2 weeks ago
Viewed 2,292 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life