Live coundown timer
Moderator: DosItHelp
Live coundown timer
Is it possible to write code that would echo a countdown timer in "minutes : seconds" of a time value that I specify? say 10 min 30 sec.
Re: Live coundown timer
yes, this is easily possible, however, more information regarding the use case would be helpful. IE: does it matter if the timer is script blocking, or do you want to just show a timer while the script is executing something else?
An example of a no frills timer that blocks script execution:
An example of a no frills timer that blocks script execution:
Code: Select all
@ECHO off
Call:Timer 10 30
Echo(done
Goto:Eof
:Timer minutes seconds
cls
setlocal
2> nul Set /A "m=%~1" || Exit /b 1
2> nul Set /A "s=%~2"
Set not0=2^>nul Set /A 1/
If not defined s Set s=0
:tloop
If %s% LSS 10 (Set os=0)Else set "os="
If %m% LSS 10 (Set om=0)Else set "om="
Echo(%om%%m%:%os%%s%
%not0% s && ( Set/A s-=1 ) || ( %not0% m && ( Set/A m-=1,s=59 ) || ( Endlocal & Exit/b ) )
Timeout /t 1 /NoBreak > nul 2>&1 || (
start "" /w /b /min mshta "javascript:setTimeout(function(){close();},1000);"
)
cls
Goto:tloop
Last edited by T3RRY on 30 Oct 2021 03:49, edited 5 times in total.
Re: Live coundown timer
That run for about 5 seconds. Also flickers something else too fast to read...
Timeout not recognized command...
Timeout not recognized command...
Re: Live coundown timer
Information like this is useful to provide when asking a question.
An alternative to timeout for you to try:
Code: Select all
start "" /w /b /min mshta "javascript:setTimeout(function(){close();},1000);"
Live coundown timer
Thank you very much!
Re: Live coundown timer
Here is another one created by Aacini on Stackoverflow some years back.
Code: Select all
@echo off
setlocal
rem Get end time
REM for /F "tokens=1,2 delims=:" %%a in ("ResponseTime.txt") do set /A endH=10%%a%%100, endM=1%%b%%100
REM Just for testing:
set endH=14
set endM=58
title Timer
mode con cols=16 lines=2
:synchronize
for /F "tokens=1,2 delims=:" %%a in ("%time%") do set /A "minutes=(endH*60+endM)-(%%a*60+1%%b-100)-1, seconds=159"
:wait
timeout /T 1 /NOBREAK > NUL
echo Timer: %minutes%:%seconds:~-2%
set /A seconds-=1
if %seconds% geq 100 goto wait
set /A minutes-=1, seconds=159, minMOD5=minutes %% 5
if %minutes% lss 0 goto :buzz
if %minMOD5% equ 0 goto synchronize
goto wait
:buzz
pause
Re: Live coundown timer
That script also uses timeout, which was not part of the standard OS for Windows XP.Gerhard wrote: ↑30 Oct 2021 00:28Here is another one created by Aacini on Stackoverflow some years back.
Code: Select all
:wait timeout /T 1 /NOBREAK > NUL
Re: Live coundown timer
Yeah, I honestly did not take note of the Windows XP comment. Thanks.atfon wrote: ↑01 Nov 2021 06:06That script also uses timeout, which was not part of the standard OS for Windows XP.Gerhard wrote: ↑30 Oct 2021 00:28Here is another one created by Aacini on Stackoverflow some years back.
Code: Select all
:wait timeout /T 1 /NOBREAK > NUL