How to convert a windows FILETIME to a std::chrono::time_point<std::chrono::file_clock> in C++

Viewed 209
1 Answers

Disclaimer: I don't have a Windows system to test on.

I believe that one just needs to take the high and low words of the FILETIME and interpret that 64 bit integral value as the number of tenths of a microsecond since the std::chrono::file_clock epoch:

FILETIME ft = ...
file_clock::duration d{(static_cast<int64_t>(ft.dwHighDateTime) << 32)
                                           | ft.dwLowDateTime};
file_clock::time_point tp{d};

Both the units and the epoch of FILETIME and file_clock (on Windows) are identical.

Related