gpt4 book ai didi

winapi - 如何将 std::chrono::high_resolution_clock::now() 转换为 Windows 文件时间(以及反向转换)

转载 作者:行者123 更新时间:2023-12-04 13:48:39 28 4
gpt4 key购买 nike

有没有办法轻松地将 std::chrono::high_resolution_clock::now() 时间转换为 Windows 文件时间 (https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx)(并返回)?我不知道如何处理这个...

非常感谢!

最佳答案

如果您有(或可能有)100 纳秒或更高精度的 time_point:

FILETIME fileTime = {0};

// Filetime has a resolution of 100nanoseconds
typedef std::chrono::duration<int64_t, std::ratio_multiply<std::hecto, std::nano>> hundrednanoseconds;

// 100nanoseconds since unix epoch + epoch offset difference of filetime
long long timePointTmp =
std::chrono::duration_cast<hundrednanoseconds>(tp.time_since_epoch()).count()
+ 116444736000000000;

fileTime.dwLowDateTime = (unsigned long)timePointTmp;
fileTime.dwHighDateTime = timePointTmp >> 32;

return fileTime;

关于winapi - 如何将 std::chrono::high_resolution_clock::now() 转换为 Windows 文件时间(以及反向转换),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30190407/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com