Formatting elapsed time

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Formatting elapsed time

Post by codude » 24 Jun 2022, 00:34

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.]

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Formatting elapsed time

Post by Xtra » 24 Jun 2022, 01:30

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
}

Rohwedder
Posts: 7673
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Formatting elapsed time

Post by Rohwedder » 24 Jun 2022, 06:14

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

User avatar
flyingDman
Posts: 2821
Joined: 29 Sep 2013, 19:01

Re: Formatting elapsed time

Post by flyingDman » 24 Jun 2022, 10:45

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
14.3 & 1.3.7

codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: Formatting elapsed time

Post by codude » 30 Jun 2022, 10:53

Thanks for all the help here. I now have something that works well.

Post Reply

Return to “Ask for Help (v1)”