如何确定VBA中的夏令时?

Lan*_*rts 4 excel vba function dst code-snippets

什么功能会告诉我们VBA中的日期是否在夏令时?

Lan*_*rts 6

对于非当前日期(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  
Run Code Online (Sandbox Code Playgroud)

然后,您可以检查DST日与以下函数调用:

秋天:NDow(年(新),
11,1,1 )春天:NDow(年(新),3,2,1)

对于当前日期:

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

我从Chip Pearson的Excel网站上获得了这个代码.

皮尔逊的网站

  • 除了这个国家不同. (2认同)