1

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;
    ULARGE_INTEGER uliTime;

    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.

Srikanth
  • 39
  • 4
  • 1
    One millisecond = 1/1000th of a second. Why are you multiplying by ten million? – tadman Sep 13 '17 at 15:51
  • The first filetime converter I looked up (http://www.silisoftware.com/tools/date.php?inputdate=1505306792&inputformat=unix), when you use its default settings and enter 1505306792, you get an output of Wednesday, September 13, 2017 12:46:32pm. Based on its default, I think you need to focus on the input format being unix. – Scott Mermelstein Sep 13 '17 at 15:52
  • There's an epoch difference: https://stackoverflow.com/questions/6161776/convert-windows-filetime-to-second-in-unix-linux – doctorlove Sep 13 '17 at 15:54

1 Answers1

3

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;
   }
Roman R.
  • 68,205
  • 6
  • 94
  • 158