How to get current system time up to milliseconds

Use the Timer function to get the current amount of Seconds (including milliseconds) elapsed since 00:00:00. This sample code will get the time in format HH:MM:SS,mmss and report it to QTP results for the current step:

lSeconds=timer() ‘gets the current time in seconds, milliseconds

lHrs = Int(lSeconds / 3600)

lMinutes = (Int(lSeconds / 60)) – (lHrs * 60)

lSeconds = lSeconds – (lHrs * 3600) – (lMinutes*60)

TransTime = lHrs &":"&lMinutes&":"&lSeconds

msgbox TransTime

Reporter.ReportEvent 2, "Transaction time", TransTime ‘ sends the formatted time to the report

Leave a Comment