public static DateTime FiletimeToDateTime(FILETIME fileTime) { if ((fileTime.dwHighDateTime == Int32.MaxValue) || (fileTime.dwHighDateTime == 0 && fileTime.dwLowDateTime == 0)) { // Not going to fit in the DateTime. In the WinInet APIs, this is // what happens when there is no FILETIME attached to the cache entry. // We're going to use DateTime.MinValue as a marker for this case. return DateTime.MaxValue; } //long hFT2 = (((long)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime; //return DateTime.FromFileTimeUtc(hFT2); SYSTEMTIME syst = new SYSTEMTIME(); SYSTEMTIME systLocal = new SYSTEMTIME(); if (0 == FileTimeToSystemTime(ref fileTime, ref syst)) { throw new ApplicationException("Error calling FileTimeToSystemTime: " + Marshal.GetLastWin32Error().ToString()); } if (0 == SystemTimeToTzSpecificLocalTime(IntPtr.Zero, ref syst, out systLocal)) { throw new ApplicationException("Error calling SystemTimeToTzSpecificLocalTime: " + Marshal.GetLastWin32Error().ToString()); } return new DateTime(systLocal.Year, systLocal.Month, systLocal.Day, systLocal.Hour, systLocal.Minute, systLocal.Second); }
public static extern long SystemTimeToTzSpecificLocalTime( IntPtr lpTimeZoneInformation, ref SYSTEMTIME lpUniversalTime, out SYSTEMTIME lpLocalTime);
public static extern long FileTimeToSystemTime(ref FILETIME FileTime, ref SYSTEMTIME SystemTime);