/// <summary>
        /// Helper routine to get a DateTime from a FILETIME.
        /// </summary>
        /// <param name="ft"></param>
        /// <returns></returns>
        public static DateTime FromFileTime(Win32API.FILETIME ft)
        {
            if (ft.dwHighDateTime == Int32.MaxValue || (ft.dwLowDateTime == 0 && ft.dwHighDateTime == 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.MinValue);
            }

            Win32API.SYSTEMTIME syst      = new Win32API.SYSTEMTIME();
            Win32API.SYSTEMTIME systLocal = new Win32API.SYSTEMTIME();
            if (0 == Win32API.FileTimeToSystemTime(ref ft, ref syst))
            {
                throw new ApplicationException("Error calling FileTimeToSystemTime: " + Marshal.GetLastWin32Error());
            }
            if (0 == Win32API.SystemTimeToTzSpecificLocalTime(IntPtr.Zero, ref syst, out systLocal))
            {
                throw new ApplicationException("Error calling SystemTimeToTzSpecificLocalTime: " + Marshal.GetLastWin32Error());
            }

            return(new DateTime(systLocal.Year, systLocal.Month, systLocal.Day, systLocal.Hour, systLocal.Minute, systLocal.Second));
        }
Exemple #2
0
		/// <summary>
		/// Helper routine to get a DateTime from a FILETIME.
		/// </summary>
		/// <param name="ft"></param>
		/// <returns></returns>
		public static DateTime FromFileTime( Win32API.FILETIME ft )
		{
			if( ft.dwHighDateTime == Int32.MaxValue || (ft.dwLowDateTime == 0 && ft.dwHighDateTime == 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.MinValue;
			}

            Win32API.SYSTEMTIME syst = new Win32API.SYSTEMTIME();
            Win32API.SYSTEMTIME systLocal = new Win32API.SYSTEMTIME();
			if( 0 == Win32API.FileTimeToSystemTime( ref ft, ref syst ) )
			{
				throw new ApplicationException( "Error calling FileTimeToSystemTime: " + Marshal.GetLastWin32Error() );
			}
			if( 0 == Win32API.SystemTimeToTzSpecificLocalTime( IntPtr.Zero, ref syst, out systLocal ) )
			{
				throw new ApplicationException( "Error calling SystemTimeToTzSpecificLocalTime: " + Marshal.GetLastWin32Error() );
			}

			return new DateTime( systLocal.Year, systLocal.Month, systLocal.Day, systLocal.Hour, systLocal.Minute, systLocal.Second );
		}