Skip to main content
GameDev.net gamedev.net
🔒 Locked

Converting FileTime to time_t on Windows

Started by wood_brian Mar 19, 2010 at 12:28 PM 2 replies 44.6k views
Original Post
wood_brian
wood_brian
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
cache_hit
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;}
wood_brian
wood_brian
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.