你可以使用我的项目VBA.Timezone-Windows中的函数BiasWindowsTimezone(下):
StartTime = #2020/11/01 00:00:00#
EndTime = #2020/11/04 00:00:00#
BiasDiff = BiasWindowsTimezone("Pacific", True, StartTime) - BiasWindowsTimezone("Pacific", True, EndTime)
BiasDiff -> -60
Excel 和 Access 的演示应用程序包括在内。如果您运行 Excel 应用程序,请务必先调用函数 ReloadTimezones 来创建包含数据的工作表。
' Returns the timezone bias as specified in Windows from
' the name (key) of a timezone entry in the Registry.
' Accepts values without the common trailing "Standard Time".
'
' If Dst is true, and the current date is within daylight saving time,
' bias for daylight saving time is returned.
' If Date1 is specified, the bias of that date is returned.
'
' Returns a bias of zero if a timezone is not found.
'
' Examples:
' Bias = BiasWindowsTimezone("Argentina")
' Bias -> 180 ' Found
'
' Bias = BiasWindowsTimezone("Argentina Standard Time")
' Bias -> 180 ' Found.
'
' Bias = BiasWindowsTimezone("Germany")
' Bias -> 0 ' Not found.
'
' Bias = BiasWindowsTimezone("Western Europe")
' Bias -> 0 ' Not found.
'
' Bias = BiasWindowsTimezone("W. Europe")
' Bias -> -60 ' Found.
'
' Bias = BiasWindowsTimezone("Paraguay", True, #2018-07-07#)
' Bias -> 240 ' Found.
'
' Bias = BiasWindowsTimezone("Paraguay", True, #2018-02-11#)
' Bias -> 180 ' Found. DST.
'
' Bias = BiasWindowsTimezone("Paraguay", False, #2018-02-11#)
' Bias -> 240 ' Found.
'
' 2018-11-16. Gustav Brock. Cactus Data ApS, CPH.
'
Public Function BiasWindowsTimezone( _
ByVal TimezoneName As String, _
Optional Dst As Boolean, _
Optional Date1 As Date) _
As Long
Static Entries() As TimezoneEntry
Static LastName As String
Static LastYear As Integer
Static Entry As TimezoneEntry
Dim ThisName As String
Dim ThisYear As Integer
Dim StandardDate As Date
Dim DaylightDate As Date
Dim DeltaBias As Long
Dim Bias As Long
If Trim(TimezoneName) = "" Then
' Nothing to look up.
Exit Function
Else
ThisName = Trim(TimezoneName)
ThisYear = Year(Date1)
If LastName = ThisName And LastYear = ThisYear Then
' Use cached data.
Else
' Retrieve the single entry or - if not found - an empty entry.
Entries = RegistryTimezoneItems(ThisName, (ThisYear))
Entry = Entries(LBound(Entries))
LastName = ThisName
LastYear = ThisYear
End If
If _
StrComp(Entry.Name, TimezoneName, vbTextCompare) = 0 Or _
StrComp(Replace(Entry.Name, StandardTimeLabel, ""), TimezoneName, vbTextCompare) = 0 Then
' Windows timezone found.
' Default is standard bias.
DeltaBias = Entry.Tzi.StandardBias
If Dst = True Then
' Return daylight bias if Date1 is of daylight saving time.
StandardDate = DateSystemTime(Entry.Tzi.StandardDate)
DaylightDate = DateSystemTime(Entry.Tzi.DaylightDate)
If DaylightDate < StandardDate Then
' Northern Hemisphere.
If DateDiff("s", DaylightDate, Date1) >= 0 And DateDiff("s", Date1, StandardDate) > 0 Then
' Daylight time.
DeltaBias = Entry.Tzi.DaylightBias
Else
' Standard time.
End If
Else
' Southern Hemisphere.
If DateDiff("s", DaylightDate, Date1) >= 0 Or DateDiff("s", Date1, StandardDate) > 0 Then
' Daylight time.
DeltaBias = Entry.Tzi.DaylightBias
Else
' Standard time.
End If
End If
End If
' Calculate total bias.
Bias = Entry.Bias + DeltaBias
End If
End If
BiasWindowsTimezone = Bias
End Function