【问题标题】:QDateTime to FILETIMEQDateTime 到 FILETIME
【发布时间】:2013-10-31 11:06:50
【问题描述】:

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

这是 MSDN 对 FILETIME 的定义:

包含一个 64 位值,表示自 1601 年 1 月 1 日 (UTC) 以来的 100 纳秒间隔数。

【问题讨论】:

    标签: c++ qt winapi


    【解决方案1】:

    我做了一个函数来做到这一点,我已经测试过它并且它可以工作:

    // 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多