如何在 vb6 中将 FILETIME 从 WinApi 转换为 DateTime?

Lou*_*hys 1 vb6 winapi

如何从 WinApi 转换 FILETIME(例如,从调用此 WINAPI 函数的结果转换为 vb6 中的 DateTime?(例如,如果我想将其用作DateTime.DateDiff函数的输入。)

Sim*_*ier 5

Public Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Public Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function SystemTimeToVariantTime Lib "OLEAUT32.DLL" (lpSystemTime As SYSTEMTIME, vtime As Date) As Long

Dim st As SYSTEMTIME
Dim dt As Date

' convert a FILETIME to SYSTEMTIME first
FileTimeToSystemTime ft, st

' convert the SYSTEMTIME to a Variant date (VT_DATE)
SystemTimeToVariantTime st, dt
Run Code Online (Sandbox Code Playgroud)

  • 稍后遇到这个问题的人应该记住,文件系统 FILETIME 值通常采用 UTC 时间,并且对于大多数用途需要进一步调整。 (2认同)