#include #include #include #include #include #include int main() { // Original timestamp, seconds since 1 Jan 1970 00:00 UTC // This corresponds to Oct 22 2014 06:17:25 UTC. qint64 timestamp = 1413958645; // This is Sep 15 2015, works fine. //timestamp = 1442301026; // Windows stores time as 100-nanosecond intervals since 1 Jan 1601 00:00 UTC unsigned long long wt = (timestamp + 11644473600LL) * 10000000LL; FILETIME ft = {DWORD(wt), DWORD(wt >> 32)}; QString filePath("test-timestamp.txt"); QFile file(filePath); if (file.open(QIODevice::Append)) { HANDLE f = (HANDLE)_get_osfhandle(file.handle()); if (!SetFileTime(f, NULL, &ft, &ft)) { qDebug() << "SetFileTime failed"; return false; } } else { qDebug() << "Could not open " << filePath << " to set modification time"; return false; } QFileInfo info(filePath); QDateTime lastModified = info.lastModified(); QDateTime lastModifiedUTC = lastModified.toUTC(); qDebug() << lastModified.timeSpec(); qint64 secondsSinceEpoch = lastModifiedUTC.toMSecsSinceEpoch() / 1000L; if (secondsSinceEpoch != timestamp) { qDebug() << "Setting file time did not work: " << secondsSinceEpoch << " vs " << timestamp; } }