Exemple #1
0
        public static DateTime?ToDateTime(this WINAPI.FILETIME time)
        {
            if ((time.dwHighDateTime == 0) && (time.dwLowDateTime == 0))
            {
                return(null);
            }

            uint dwLowDateTime = (uint)time.dwLowDateTime;

#pragma warning disable CS0675 // Bitwise-or operator used on a sign-extended operand
            long fileTime = (time.dwHighDateTime << 0x20) | dwLowDateTime;
#pragma warning restore CS0675 // Bitwise-or operator used on a sign-extended operand
            return(new DateTime?(DateTime.FromFileTimeUtc(fileTime)));
        }
Exemple #2
0
        /// <summary>
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static DateTime?ToDateTime(this WINAPI.FILETIME time)
        {
            if (time.dwHighDateTime == 0 && time.dwLowDateTime == 0)
            {
                return(null);
            }

            unchecked
            {
                uint low = (uint)time.dwLowDateTime;
                long ft  = (((long)time.dwHighDateTime) << 32 | low);
                return(DateTime.FromFileTimeUtc(ft));
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="time"> </param>
        /// <returns> </returns>
        public static DateTime?ToDateTime(this WINAPI.FILETIME time)
        {
            switch (time.dwHighDateTime)
            {
            case 0 when time.dwLowDateTime == 0:
            case 0 when time.dwLowDateTime == 0:
                return(null);

            default:
                unchecked
                {
                    uint low = (uint)time.dwLowDateTime;
                    long ft  = ((long)time.dwHighDateTime << 32) | low;
                    return(DateTime.FromFileTimeUtc(ft));
                }
            }
        }