@msdn=http://search.microsoft.com/search/results.aspx?qu=$$$ @pinvoke=http://pinvoke.net/$$$.htm Summary: FILETIME !!!!C# Definition: [StructLayout(LayoutKind.Sequential)] public struct FILETIME { public uint DateTimeLow; public uint DateTimeHigh; } !!!!VB.Net Definition: <StructLayout(LayoutKind.Sequential)> _ Public Structure FILETIME Public dwLowDateTime As UInteger Public dwHighDateTime As UInteger Public ReadOnly Property Value() As ULong Get Return CType(dwHighDateTime << 32, ULong) + dwLowDateTime End Get End Property End Structure !!!!Alternative Managed Definition: System.Runtime.InteropServices.FILETIME@msdn (obsolete), or System.Runtime.InteropServices.ComTypes.FILETIME@msdn in the .NET Framework 2.0. !!!!Notes: None. !!!!Sample Code: There is no reason not to use System.Runtime.InteropServices.ComTypes.FILETIME@msdn, but there still is a need for conversion to DateTime@msdn: C# public static DateTime FiletimeToDateTime(FILETIME fileTime) { long hFT2 = (((long) fileTime.dwHighDateTime) << 32) | ((uint) 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. * Note that System.Runtime.InteropServices.FILETIME is now obsolete. Changed to use System.Runtime.InteropServices.ComTypes.FILETIME instead. This works for me in vb.net: Private Shared Function ConvertFileTimeToDateTime(input As FILETIME) As DateTime Dim longTime As ULong = (CType(input.dwHighDateTime, ULong) << 32) Or input.dwLowDateTime Return DateTime.FromFileTime(longTime) End Function --- Completely without any error-prone bit shift operations: C# [StructLayout(LayoutKind.Sequential)] struct FILETIME { private long timestamp; public DateTime Local { get { return DateTime.FromFileTime(this.timestamp); } set { this.timestamp = value.ToFileTime(); } } public DateTime Utc { get { return DateTime.FromFileTimeUtc(this.timestamp); } set { this.timestamp = value.ToFileTimeUtc(); } } } Documentation: FILETIME@msdn on MSDN
Edit Structures.FileTime
You do not have permission to change this page. If you feel this is in error, please send feedback with the contact link on the main page.