Now() Accuracy in VBScript

2019-08-15 03:49发布

问题:

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.