I'm building a TimeStamp function for logging in a vbs app that I'm building. I don't want to use the Now() because that only shows to seconds, I want to show milliseconds. Some reading has shown that using the Timer() function may be better for my requirements.
I wrote the below code, but was wondering if there is a more efficient or better way of getting millisecond based time stamps.
I wrote the below code, but was wondering if there is a more efficient or better way of getting millisecond based time stamps.
Code:
Function TimeStamp()
Dim Temp, iHour, iMinute, iSecond
Temp = Timer/3600
iHour = Int(temp)
iMinute = Int((temp - iHour) * 60)
iSecond = Int((((temp - iHour) * 60 - iMinute) * 60)*1000)/1000
'2 digit hour
If Len(iHour) < 2 Then
iHour = "0" & CStr(iHour)
Else
iHour = CStr(iHour)
End If
'2 digit minute
If Len(iMinute) < 2 Then
iMinute = "0" & CStr(iMinute)
Else
iMinute = CStr(iMinute)
End If
'2 digit second
If Len(Int(iSecond)) < 2 Then
iSecond = "0" & CStr(iSecond)
Else
iSecond = CStr(iSecond)
End If
'3 digit hundredths
If Len(iSecond) < 6 Then
iSecond = iSecond & "0"
End If
TimeStamp = Date & " " & iHour & ":" & iMinute & ":" & iSecond
End Function