FILETIME 互转 DateTime 待验证

xiaoxiao2021-02-28  94

http://blog.163.com/mingwang_ok/blog/static/18436570200773075452554/

HOW TO: convert a System.Runtime.InteropServices.FILETIME into a System.DateTime and back again

Added On: 12/14/2003 Blurb Eventually, everyone works with an unmanaged Win32 API in .NET that returns you information in the form of a FILETIME struct. But, a .NET programmer is used to working with a DateTime struct. This code converts FILETIME to DateTime and DateTime to FILETIME... just everything a growing programmer needs. Sample C# Code using System; using System.Runtime.InteropServices; namespace ClassLibrary3 { class __Loader { // HOWTO: convert a System.Runtime.InteropServices.FILETIME // into a System.DateTime and back again static void Main() { FILETIME ft = new FILETIME(); / //from System.DateTime to System.Runtime.InteropServices.FILETIME / long hFT1 = DateTime.Now.ToFileTimeUtc(); ft.dwLowDateTime = (int) (hFT1 & 0xFFFFFFFF); ft.dwHighDateTime = (int) (hFT1 >> 32); / //from System.Runtime.InteropServices.FILETIME to System.DateTime / long hFT2 = (((long) ft.dwHighDateTime) << 32) + ft.dwLowDateTime; DateTime dte = DateTime.FromFileTimeUtc(hFT2); Console.WriteLine(dte); } } }

转载请注明原文地址: https://www.6miu.com/read-80780.html

最新回复(0)