1

I want to convert Windows FILETIME structure to Unix Epoch format and vice versa. I need to write two functions:

UINT64 GetEpoch(FILETIME ft)
{
  UINT64 llEpoch;
 //Code that converts ft to epoch
  return llEpoch;
}

FILETIME GetFileTime(UINT64 llEpoch)
{
  FILETIME ft;
  //Code that converts epoch to FILETIME
  return ft;
}

It is essential that epoch value is in milliseconds. I have tried this article

Convert Windows Filetime to second in Unix/Linux

I have written function to convert Epoch to FILETIME using above article. It looks like this:

#define MILI_SEC_TO_UNIX_EPOCH 116444736000000000LL

FILETIME CTimeUtils::MillisToFileTime(UINT64 millis)
{
    UINT64 multiplier = 10000;
    UINT64 t = (multiplier * millis) + MILI_SEC_TO_UNIX_EPOCH;

    ULARGE_INTEGER li;
    li.QuadPart = t;
    // NOTE, DON'T have to do this any longer because we're putting
    // in the 64bit UINT directly
    //li.LowPart = static_cast<DWORD>(t & 0xFFFFFFFF);
    //li.HighPart = static_cast<DWORD>(t >> 32);

    FILETIME ft;
    ft.dwLowDateTime = li.LowPart;
    ft.dwHighDateTime = li.HighPart;

    return ft;
}

But I haven't figured out how to convert FILETIME to epoch with milliseconds resolution.

Community
  • 1
  • 1
Ram
  • 1,225
  • 2
  • 24
  • 48
  • Well, clearly, if `filetime == (multiplier * millis) + MILI_SEC_TO_UNIX_EPOCH`, then `millis == (filetime - MILI_SEC_TO_UNIX_EPOCH) / multiplier` – Igor Tandetnik Dec 07 '16 at 12:42

0 Answers0