如何在 C++ 中将 windows FILETIME 转换为 std::chrono::time_point<std::chrono::file_clock>

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

我正在寻找一种方法来转换 Windows FILETIME structure to a std::chrono::time_point< std::chrono::file_clock> so that I can build a difference between two file times and express that duration f.e. in std::chrono::microseconds

编辑Here is a complete godbolt example of .

免责声明:我没有 Windows 系统可以测试。

我认为只需要取 FILETIME 的高位字和低位字并将该 64 位整数值解释为自 std::chrono::file_clock 纪元以来的十分之一微秒数:

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

FILETIMEfile_clock(在Windows)的单位和纪元是相同的。