vba經過API函數獲取電腦操做系統的時區。函數
#If Win64 Then Private Declare PtrSafe Sub GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) #Else Private Declare Sub GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) #End If Private 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 Type TIME_ZONE_INFORMATION Bias As Long StandardName(32) As Integer StandardDate As SYSTEMTIME StandardBias As Long DaylightName(32) As Integer DaylightDate As SYSTEMTIME DaylightBias As Long End Type Sub xx()Dim b As TIME_ZONE_INFORMATION Dim Zone As Integer GetSystemTime a GetTimeZoneInformation b Zone = b.Bias / 60 MsgBox Zone End Sub
結果返回-8,表示世界時間比中國時間晚8小時,即所在時區位於東八區。spa