我希望得到毫秒的时间 目前使用Timer()方法,但它只提供第二次访问 任何的想法?
请确保我不想将秒转换为毫秒,希望得到毫秒
答案 0 :(得分:16)
实际上,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
答案 1 :(得分:0)
根据MBu的回答,这是一个Sub版本。在您的代码周围为即时窗口中的消息撒上调用,以便您可以看到发生延迟的位置。
' *** 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
答案 2 :(得分:0)
这使用vbs中的标准日期
'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