恭喜,你发布的帖子
发布于 2021-03-01 19:25:30
5楼
Function GetLocalDate(vtDate)
Dim DoY
Dim dso
Dim dwi
Dim strComputer, objWMIService, colItems, objItem
Dim TimeZone
Dim vtDateLocalDate
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objItem In colItems
TimeZone = objItem.Bias / 60 'offset TimeZone In hours
Next
If IsDate(vtDate) <> True Then
IS_GetLocalDate = False
Exit Function
End If
DoY = DatePart("y", vtDate)
dso = DatePart("y", "31.03") - DatePart("w", "31.03") + 1
dwi = DatePart("y", "31.10") - DatePart("w", "31.10") + 1
If DoY >= dso And DoY < dwi Then
'sommer
TimeZone = TimeZone + 1 'additional offset 1h in summer
End If
vtDateLocalDate = DateAdd("h", 1 * TimeZone, vtDate)
GetLocalDate = vtDateLocalDate
End Function
更多关于时间转换的信息请参考连接:
如何将本地计算机时间的时间戳(日期时间)转换成协调世界时 (UTC)? 24201113
这个函数是有问题的, 他花费了很大的篇幅,在计算夏时制,然后会导致中国在夏季的时候时间错了1个小时. .
请填写推广理由:
分享
只看
楼主