如何确定VBA中的夏令时?

时间:2020-03-06 14:41:55  来源:igfitidea点击:

什么功能可以让我们知道VBA中的日期是否在DST中?

解决方案

对于非当前日期(DST 2007+):

首先,我们需要一个函数来查找一个月中特定工作日的数量:

Public Function NDow(Y As Integer, M As Integer, _
                N As Integer, DOW As Integer) As Date  

' Returns Date of Nth Day of the Week in Month  

NDow = DateSerial(Y, M, (8 - Weekday(DateSerial(Y, M, 1), _
              (DOW + 1) Mod 8)) + ((N - 1) * 7))  

End Function

然后,我们可以对照以下函数调用来检查夏令时的日期:

秋季:NDow(Year(newdate),11、1、1)
春季:NDow(Year(newdate),3,2,1)

对于当前日期:

调用Windows API函数GetTimeZoneInformation,
它将返回一个带有状态的枚举(整数)。

我从Chip Pearson的出色Excel网站获得了此代码。

皮尔森的网站