Article

When working with Win32 FILETIME, don’t forget that you have std::chrono now

Not specified ·The Old New Thing ·Published 2026-09-23 ·5 min read

This article discusses how to simplify the calculation of time differences using std::chrono in C++ instead of manually handling FILETIME. It highlights the benefits of using modern C++ libraries for better code clarity and efficiency.

From the article

Some time ago, I was looking at a pull request, and saw that the code was manually calculating the “number of minutes since the last change” by doing annoying math.

static const DWORD c_TicksPerSecond = 10000000; static const DWORD c_SecondsPerMinute = 60; uint64_t FileTimeToULongLong(FILETIME time) { ULARGE_INTEGER value; value.LowPart = time.dwLowDateTime; value.HighPart = time.dwHighDateTime; return value.QuadPart; } DWORD GetMinutesSinceLastChange() { FILETIME now; GetSystemTimeAsFileTime(&now); uint64_t now64 = FileTimeToULongLong(now); uint64_t last64 = FileTimeToULongLong(m_lastChange); if (now64 < last64) { return 0; } uint64_t diff = last64 - now64; return static_cast<DWORD>(diff / (static_cast<uint64_t>(c_dwSecondsPerMinute) * static_cast<uint64_t>(c_TicksPerSecond))); } Okay…


Share this resource


Discovered 2026-09-24 Source The Old New Thing Archive 2026-09 →