Live coundown timer
Posted: 29 Oct 2021 11:34
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.
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
Information like this is useful to provide when asking a question.
Code: Select all
start "" /w /b /min mshta "javascript:setTimeout(function(){close();},1000);"
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
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
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