Here is the code to convert FILETIME to Unix Time (__time64_t). You can also use time_t instead of __time64_t.
__time64_t FileTimeToUnixTime(FILETIME & ft) { ULARGE_INTEGER ull; ull.LowPart = ft.dwLowDateTime; ull.HighPart = ft.dwHighDateTime; return ull.QuadPart / 10000000ULL - 11644473600ULL; } |
Unix time (__time64_t or time_t) to FILETIME
Here is the code to convert unix time (__time64_t) to FILETIME. You can also use time_t, in which case you would need to use Int32x32to64(t, 10000000) function to multiply in the below code.
void UnixTimeToFileTime(__time64_t t, FILETIME * pFT) { // Note that LONGLONG is a 64-bit value LONGLONG ll; ll = (t * 10000000) + 116444736000000000; pFT->dwLowDateTime = (DWORD)ll; pFT->dwHighDateTime = ll >> 32; } |