gpt4 book ai didi

c++ - QDateTime 到 FILETIME

转载 作者:行者123 更新时间:2023-11-28 03:05:56 29 4
gpt4 key购买 nike

我需要将 QDateTime 传递给接受 FILETIME 的 Win32 函数.

这是 MSDN 对 FILETIME 的定义:

Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

最佳答案

我编写了一个函数来执行此操作,我已经对其进行了测试并且可以正常工作:

// Convert a QDateTime to a FILETIME.
FILETIME toWinFileTime(const QDateTime &dateTime)
{
// Definition of FILETIME from MSDN:
// Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
QDateTime origin(QDate(1601, 1, 1), QTime(0, 0, 0, 0), Qt::UTC);
// Get offset - note we need 100-nanosecond intervals, hence we multiply by
// 10000.
qint64 _100nanosecs = 10000 * origin.msecsTo(dateTime);
// Pack _100nanosecs into the structure.
FILETIME fileTime;
fileTime.dwLowDateTime = _100nanosecs;
fileTime.dwHighDateTime = (_100nanosecs >> 32);
return fileTime;
}

关于c++ - QDateTime 到 FILETIME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19704817/

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