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 GetTimeZoneInformation b Zone = b.Bias / 60 MsgBox Zone End Sub

结果返回-8,表示世界时间比中国时间晚8小时,即所在时区位于东八区。