As per https://msdn.microsoft.com/en-us/library/windows/desktop/ms724290(v=vs.85).aspx, a file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).
To convert between SystemTime
and FileTime
, the Windows API functions SystemTimeToFileTime
and FileTimeToSystemTime
can be used.
I'm probably missing something here, because I don't think that this is a too rare task. However, searching SO for [.net] systemtimetofiletime
provides as results just one (downvoted) answer and no relevant questions.
Perhaps it's just a lack of knowledge about the proper terminology, and SystemTimeToFileTime
is called something very different in the .Net world.
Anyway, the question is, how do I properly convert between SystemTime
and FileTime
in .Net?
Declare the PInvoke function and call it.
Personally, I search the .NET Framework with a decompiler such as Reflector in such cases for existing usages. Often, Microsoft has already internally called the API that I need. Likely, their PInvoke code will be correct and ready to copy.