我需要计算两个时间戳之间的差异(以毫秒为单位)。
不幸的是,VBA 的 DateDiff 函数不提供这种精度。
有什么解决方法吗?
您可以使用描述的方法here http://www.tek-tips.com/faqs.cfm?fid=2292如下:-
创建一个名为的新类模块StopWatch
将以下代码放入StopWatch
类模块:
Private mlngStart As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Sub StartTimer()
mlngStart = GetTickCount
End Sub
Public Function EndTimer() As Long
EndTimer = (GetTickCount - mlngStart)
End Function
您可以按如下方式使用代码:
Dim sw as StopWatch
Set sw = New StopWatch
sw.StartTimer
' Do whatever you want to time here
Debug.Print "That took: " & sw.EndTimer & "milliseconds"
其他方法描述了 VBA 计时器函数的使用,但这仅精确到百分之一秒(厘秒)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)