Converting FileTime to time_t on Windows

Started by
2 comments, last by wood_brian 14 years, 1 month ago
I need some help figuring out how to get the time a file was last modified as a time_t on Windows. On Linux I use fstat. I'm not sure how to convert the results of GetFileTime to a time_t. Thanks in advance. Brian Wood http://webEbenezer.net (651) 251-9384
Advertisement
A FILETIME is the number of 100-nanosecond intervals since January 1, 1601.
A time_t is the number of 1-second intervals since January 1, 1970.

From there you can derive the following:

time_t filetime_to_timet(const FILETIME& ft){   ULARGE_INTEGER ull;   ull.LowPart = ft.LowPart;   ull.HighPart = ft.HighPart;   return ull.QuadPart / 10000000ULL - 11644473600ULL;}
You can also use _fstat on Windows as well.
Quote:Original post by cache_hit
A FILETIME is the number of 100-nanosecond intervals since January 1, 1601.
A time_t is the number of 1-second intervals since January 1, 1970.

From there you can derive the following:

time_t filetime_to_timet(const FILETIME& ft){   ULARGE_INTEGER ull;   ull.LowPart = ft.LowPart;   ull.HighPart = ft.HighPart;   return ull.QuadPart / 10000000ULL - 11644473600ULL;}





Thanks for that. That seems to be working with two minor changes:

  time_t  filetime_to_timet(FILETIME const& ft) const  {    ULARGE_INTEGER ull;    ull.LowPart = ft.dwLowDateTime;    ull.HighPart = ft.dwHighDateTime;    return ull.QuadPart / 10000000ULL - 11644473600ULL;  }


Brian Wood
http://webEbenezer.net
(651) 251-9384

This topic is closed to new replies.

Advertisement