How to create a batch file countdown timer in min:

2019-04-15 21:56发布

I am trying to create a countdown timer that is in min:sec format which uses a variable taken from a text document and uses it as the finish time and uses the current time (time the .bat was started) as the start time. Currently I have this code which works and gets the time from the text document but I can't seem to figure out how to use get it to work.

Code:

@echo off

set CurrentTime=%time:~0,2%.%time:~3,2%

set /p StartTime=<"ResponseTime.txt"

echo.

echo %CurrentTime% %StartTIme%

echo.

3条回答
聊天终结者
2楼-- · 2019-04-15 22:09
@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
查看更多
来,给爷笑一个
3楼-- · 2019-04-15 22:22

What I would do is create a timeout function such as timeout /t xx where xx equals the time in seconds. If that is what you're looking for.

You can also do timeout /t xx >nul so that it won't display a message saying how many seconds you have left. If that is what you want then use the first one I showed. I hope this helped

查看更多
ゆ 、 Hurt°
4楼-- · 2019-04-15 22:25

Works perfect

@echo off

timeout /t 10>NUL start chrome "https://google.com"

查看更多
登录 后发表回答