• Advertisement
Sign in to follow this  

Converting FileTime to time_t on Windows

This topic is 2899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement