Skip to content

Instantly share code, notes, and snippets.

@CommanderPho
Created July 25, 2019 19:23
Show Gist options
  • Save CommanderPho/7bd2f6195a5756edbbe2065828f23c1c to your computer and use it in GitHub Desktop.
Save CommanderPho/7bd2f6195a5756edbbe2065828f23c1c to your computer and use it in GitHub Desktop.
Converts a Win32 FileTime into a POSIX LONGLONG Timestamp. Credit (https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/)
// Converts a windows FILETIME structure to a POSIX timestamp
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
LONGLONG FileTime_to_POSIX(FILETIME ft)
{
// takes the last modified date
LARGE_INTEGER date, adjust;
date.HighPart = ft.dwHighDateTime;
date.LowPart = ft.dwLowDateTime;
// 100-nanoseconds = milliseconds * 10000
adjust.QuadPart = 11644473600000 * 10000;
// removes the diff between 1970 and 1601
date.QuadPart -= adjust.QuadPart;
// converts back from 100-nanoseconds to seconds
return date.QuadPart / 10000000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment