VBA如何獲取電腦操作系統的時區


#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小時,即所在時區位於東八區。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章