Page 1 of 1

Formatting elapsed time

Posted: 24 Jun 2022, 00:34
by codude
Hello, I can’t figure out how to make the last line of this code read the way I want. If the script is run and the wait time is say 73 seconds I want the last Msgbox to return this. "00:01:13".

Code: Select all

-::
TimeStart := A_Now
Msgbox, wait
EndTime   := A_now
formattime,a,%timestart%      ,HH:mm:ss
formattime,b,%endtime% ,HH:mm:ss
msgbox,START   =%a%
msgbox,End   =%b%
ElapsedSeconds := (EndTime - TimeStart)        
Msgbox, ElapsedSeconds - %ElapsedSeconds%  
formattime,c,%elapsedseconds%      ,HH:mm:ss
Msgbox, Time  =%c%   
return
[Mod edit: [code][/code] tags added.]

Re: Formatting elapsed time

Posted: 24 Jun 2022, 01:30
by Xtra
A different approach:

Code: Select all

-::
TimeStart := A_TickCount
Msgbox, wait
EndTime   := A_TickCount

c := Format_Msec(EndTime - TimeStart)

Msgbox, Time = %c%
return

Format_Msec(ms) {
    VarSetCapacity(t,256),DllCall("GetDurationFormat","uint",2048,"uint",0,"ptr",0,"int64",ms*10000,"wstr","hh':'mm':'ss","wstr",t,"int",256)
    return t
}

Re: Formatting elapsed time

Posted: 24 Jun 2022, 06:14
by Rohwedder
Hallo,
try:

Code: Select all

Msgbox, wait
EndTime   := A_now
formattime, a, %timestart%, HH:mm:ss
formattime, b, %endtime%, HH:mm:ss
msgbox, START   =%a%
msgbox, End   =%b%
ElapsedSeconds := EndTime 
ElapsedSeconds -= TimeStart , Seconds ;EnvSub      
Msgbox, ElapsedSeconds -%ElapsedSeconds% 
Time := 20220101
Time += ElapsedSeconds, Seconds ;EnvAdd
FormatTime, Time,% Time, HH:mm:ss
Msgbox, Time  =%Time%   
return

Re: Formatting elapsed time

Posted: 24 Jun 2022, 10:45
by flyingDman
Or

Code: Select all

SecStrt := A_Now
msgbox wait
SecFnsh   := A_Now
SecFnsh -= SecStrt, seconds
MsgBox, % Format("{:02}:{:02}:{:02}", Floor(SecFnsh/3600), Floor(Mod(SecFnsh, 3600)/60), Mod(SecFnsh, 60))
return

Re: Formatting elapsed time

Posted: 30 Jun 2022, 10:53
by codude
Thanks for all the help here. I now have something that works well.