Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

FileTime (Structures)
 
.
Summary
FILETIME

C# Definition:

[StructLayout(LayoutKind.Sequential)]
struct FILETIME {
    public uint DateTimeLow;
    public uint DateTimeHigh;
}

VB.Net Definition:

Structure FILETIME
   Public dwLowDateTime As Integer
   Public dwHighDateTime As Integer
End Structure

Alternative Managed Definition:

System.Runtime.InteropServices.FILETIME, or System.Runtime.InteropServices.ComTypes.FILETIME in the .NET Framework 2.0.

Notes:

None.

Sample Code:

There is no reason not to use System.Runtime.InteropServices.FILETIME, but there still is a need for conversion to DateTime:

C#

    public static DateTime FiletimeToDateTime(FILETIME fileTime) {
        long hFT2 = (((long) fileTime.dwHighDateTime) << 32) | fileTime.dwLowDateTime;
        return DateTime.FromFileTimeUtc(hFT2);
    }

    public static FILETIME DateTimeToFiletime(DateTime time) {
        FILETIME ft;
        long hFT1 = time.ToFileTimeUtc();
        ft.dwLowDateTime = (int) (hFT1 & 0xFFFFFFFF);
        ft.dwHighDateTime = (int) (hFT1 >> 32);
        return ft;
    }

Actually, this is NOT working. The only solution I've found so far is using the API Kernel32.dll function FileTimeToSystemTime, then transforming from that into a regular DateTime.

The reason it was not working, is the + operator between "((long) high) << 32" and "low". I changed this to the | operator.

Documentation
FILETIME on MSDN

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions