cypher175

How Can I Display TimerDiff() in H,M,S Format..?

9 posts in this topic

#1 ·  Posted (edited)

How Can I Display the TimerDiff($Timer) in (Hour, Min, Sec) (00:00:00) Format for the ToolTip..??

while 1
$Timer = TimerInit()
sleep(10000)
$Time = TimerDiff($Timer)
ToolTip($Time)
Sleep(1500)
wend
Edited by cypher175

Share this post


Link to post
Share on other sites



func _Diff2Time($TimerDiff)
    
    dim $HMS[3]
    
    $HMS[2] = Int($TimerDiff / 1000)
    $HMS[1] = $HMS[2] - Mod($HMS[2], 60)
    $HMS[2] -= $HMS[1]
    $HMS[1] /= 60
    $HMS[0] = $HMS[1] - Mod($HMS[1], 60)
    $HMS[1] -= $HMS[0]
    $HMS[0] /= 60
    return $HMS
endfunc; _Diff2Time

local $Diff = 60000
local $Time = _Diff2Time($Diff)
ConsoleWrite($Time[0] & ':' & $Time[1] & ':' & $Time[2] & ' (Hour:Min:Sec)' & @CR)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ahh well beaten , never mind :)

$time = 0
$Timer = TimerInit()
While 1
    $time = TimerDiff($Timer)
    Sleep(1000)
    $hour = Floor($time / 3600000)
    $remanH = Mod($time, 3600000)
    $min = Floor($remanH / 60000)
    $remanM = Mod($remanH, 60000)
    $sec = Floor($remanM / 1000)
    ToolTip($hour & ":" & $min & ":" & $sec)
WEnd
Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

cypher175,

You can let Autoit do all the sums for you if you prefer: ;-)

#Include <Date.au3>
Global $iHours = 0, $iMins = 0, $iSecs = 0
$iBegin = TimerInit()
Sleep(5000)
$iEnd = TimerDiff($iBegin)
_TicksToTime($iEnd, $iHours, $iMins, $iSecs)
ConsoleWrite(StringFormat("%02d:%02d:%02d", $iHours, $iMins, $iSecs) & @CRLF)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

we cant imagine your problems

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

First, a million thanks to Yashied, JackDinn, and Melba 23 for providing very useful examples.

The final routine I constructed is a hybrid borrowing logic from all three examples, plus additional logic and a formatted string for presenting milliseconds. It is surprisingly accurate despite not using API calls to the system clock. This routine will be used for other purposes, but it was initially created to record and trend the time required for an external application to launch and become active.

In this instance, millisecond accuracy wasn't important since the external program requires around 30 seconds to launch, but other routines will be timing data transfer response times which will require sub-second accuracy.

 

;Millisecond Timer (First used to record elapsed time for GUI Time Clock Launch)
;Thanks to Yashied, JackDinn, and Melba23 on the AutoIt forums!

#include <DateTimeConstants.au3>
#include <Date.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>

Global $tmrStartTime
Global $tmrELTime
Global $tmrCalc
Global $iHours = 0
Global $iMins = 0
Global $iSecs = 0
Global $iMSecs = 0



$tmrStartTime = TimerInit()

;(Do Stuff that takes a while)

$tmrELTime = TimerDiff($tmrStartTime)
_TicksToTime($tmrELTime, $iHours, $iMins, $iSecs)

$tmrCalc = $iHours * 3600000
$tmrCalc = $tmrCalc + $iMins * 60000
$tmrCalc = $tmrCalc + $iSecs * 1000
$iMSecs = Int(Number($tmrELTime) - Number($tmrCalc))

$logtext = "Function cmdLTC - GUI TC Loading Elapsed Time: " & StringFormat("%02d:%02d:%02d.%03d", $iHours, $iMins, $iSecs, $iMSecs)
writelog($logtext)

The routine assigns time values automatically from the TimerDiff function for hours, minutes, and seconds as usual, but the millisecond value is calculated by back-converting each time value for hours, minutes, and seconds to milliseconds, adding them together, and subtracting this total from the raw value returned by TimerDiff. The result is stored in $iMSecs, and then formatted with the addition of the .%03d filter, and the $iMsecs variable to the string list.

I suppose I could have tried simply adding the iMSecs variable to the _TicksToTime function, which I didn't because I'm sort of gutless that way. Plus, the AutoIt help files said that the _TicksToTime function only returns hours, minutes and seconds, so I was convinced that if I attempted to add the variable, the system would probably crash, delete the OS, and catch fire, or worse, throw up an "invalid parameters" error ;-)

Edited by mbunds
Stripped some irrelevant code from the code example.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now