使用VBScript以毫秒为单位查找时间

使用VBScript以毫秒为单位查找时间,vbscript,Vbscript,我想用毫秒来计算时间 当前正在使用Timer()方法,但它只允许每秒访问 有什么想法吗 请确保我不想将秒转换为毫秒。我想用毫秒来获取秒数。事实上,计时器函数会用毫秒来表示秒数。返回值的整数部分是从午夜开始的秒数,分数部分可以转换为毫秒,只需将其乘以1000即可 t = Timer ' Int() behaves exactly like Floor() function, i.e. it returns the biggest integer lower than function's arg

我想用毫秒来计算时间 当前正在使用Timer()方法,但它只允许每秒访问 有什么想法吗


请确保我不想将秒转换为毫秒。我想用毫秒来获取秒数。事实上,计时器函数会用毫秒来表示秒数。返回值的整数部分是从午夜开始的秒数,分数部分可以转换为毫秒,只需将其乘以1000即可

t = Timer

' Int() behaves exactly like Floor() function, i.e. it returns the biggest integer lower than function's argument
temp = Int(t)

Milliseconds = Int((t-temp) * 1000)

Seconds = temp mod 60
temp    = Int(temp/60)
Minutes = temp mod 60
Hours   = Int(temp/60)

WScript.Echo Hours, Minutes, Seconds, Milliseconds

' Let's format it
strTime =           String(2 - Len(Hours), "0") & Hours & ":"
strTime = strTime & String(2 - Len(Minutes), "0") & Minutes & ":"
strTime = strTime & String(2 - Len(Seconds), "0") & Seconds & "."
strTime = strTime & String(4 - Len(Milliseconds), "0") & Milliseconds

WScript.Echo strTime

基于MBu的回答,这里有一个子版本。在即时窗口中的消息代码周围散布对此的调用,以便查看延迟发生的位置

' *** Debug.Print the time with milliseconds, and a message of your choice
Private Sub DebugPrintTime(strWhereFrom As String)
On Error GoTo ErrHandler

    Dim sglTimer As Single
    Dim sglWholeSecs As Single
    Dim Millisecs As Variant  ' as a variant, Len() will give the length of string representation of this value
    Dim Seconds As Variant
    Dim Minutes As Variant
    Dim Hours As Variant
    Dim strTime As String

    sglTimer = timer
    sglWholeSecs = Int(sglTimer)
    Millisecs = Int((sglTimer - sglWholeSecs) * 1000)
    Seconds = sglWholeSecs Mod 60
    sglWholeSecs = Int(sglWholeSecs / 60)
    Minutes = sglWholeSecs Mod 60
    Hours = Int(sglWholeSecs / 60)

    strTime = String(2 - Len(Hours), "0") & Hours & ":"
    strTime = strTime & String(2 - Len(Minutes), "0") & Minutes & ":"
    strTime = strTime & String(2 - Len(Seconds), "0") & Seconds & "."
    strTime = strTime & String(3 - Len(Millisecs), "0") & Millisecs
    Debug.Print strTime, strWhereFrom

    Exit Sub
ErrHandler:
    MsgBox "Error in Sub DebugPrintTime" & vbCrLf & Err.Description & vbCrLf & strWhereFrom
    Err.Clear
End Sub

这使用vbs中的标准dateserial

'get a timeserial with milliseconds
d1= date+ timer/86400
Wscript.echo datestamp(d1)&" "& timestamp(d1)

function datestamp(d)
  datestamp=year(d) &"/"& month(d) & "/" & day(d)
 end function

function timestamp(d)
  ymd=fix(d)
  h=hour(d)
  m=minute(d)
  s=second(d)
  timestamp=right("00" & h,2)&":"& right("00" & m,2)& ":" & right("00" & s,2)& ","& _
  right("000"& 86400000*(d-timeserial(h,m,s)-ymd),3)
end function  

这不是VBScript。事实上,VB(6)更像。