问题描述
有什么功能让我们知道VBA中的日期是否在DST中?
What function will let us know whether a date in VBA is in DST or not?
推荐答案
- 当前日期(DST 2007 +):
首先,您需要一个函数来查找一个月内特定工作日的数量:
First, you need a function to find the number of specific weekdays in a month:
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
然后,您可以检查DST日期与以下函数调用:
Then, you can check for the DST day versus the following function calls:
下降:NDow(Year(newdate),11, 1,1)
Spring:NDow(Year(newdate),3,2,1)
Fall: NDow(Year(newdate), 11, 1, 1)
Spring: NDow(Year(newdate), 3, 2, 1)
对于当前日期: / b>
For the current date:
调用Windows API函数GetTimeZoneInformation,
,它将返回枚举(整数)机智h的状态。
Call the Windows API function GetTimeZoneInformation,and it will return an enum (integer) with the status.
我从Chip Pearson的超级Excel网站获得了代码。
I got the code for this from Chip Pearson's great Excel site.
这篇关于您如何确定VBA中的夏令时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!