Now() Accuracy in VBScript

走远了吗. 提交于 2019-12-13 17:57:44

问题


Now() in VBScript appears to return time in 10,000,000th of a second precision when called as CDbl(Now()). In attempting to use this to write a more accurate implementation of now which returns CIM_DATETIME format I found that in VBScript, despite being particularly precise, is not very accurate with the time only updating once per second. This can be demonstrated by watching the output from what follows:

i = 0
While i < 50
    gnow = Cdbl(now) 
    result = (gnow - Int(gnow))
    WScript.Echo CDate(gnow)
    WScript.Echo "Iteration " & i & ": " & result
    WScript.Sleep(100)
    i = i + 1
Wend

The question I'm now trying to answer is, given a VBScript that runs for less than a second which calls Now(), what time will be returned by Now()? Is it the time that the script interpreter started, the time when Now() was called, or something else?


回答1:


It looks like it will be the time the "Now()" method was called accurate to the second. It's still a normal method invocation.



来源:https://stackoverflow.com/questions/1239169/now-accuracy-in-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!