2

我想创建一个批处理文件倒数计时器(由于存在限制,需要是批处理脚本)。到目前为止,我已经使用了两个脚本来“有点”完成这项工作,但也有它们自己的缺点。

条件如下: 1. 需要以 xx:xx:xx 格式显示系统时间。2. 需要以分+秒为单位倒计时,格式为xx:xx。3. 需要能够在 12 小时内工作(例如晚上 7 点到早上 7 点)

我一直在使用的倒计时脚本(不是我自己创作的,我只是修改了某些部分)如下:

@echo off
setlocal

REM This script starts countdown from time you open batch file.
REM Open at 19:00:23 and it will finish at 07:00:23 (it's range is 60 seconds) 
REM This can be checked against http://www.rechnr.com/online-calculator/how-many-hours-left-until-tomorrow-calculator.html

:settime1

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=07
set endM=00

title Timer
mode con cols=20 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 Shift End:  %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
mode con cols=100 lines=30
echo End of Shift
SET /P ANSWER=Would you like to shut down the machine (Y/N)? 
echo You chose: %ANSWER% 
if /i {%ANSWER%}=={y} (goto :yes) 
if /i {%ANSWER%}=={yes} (goto :yes) 
goto :no 
:yes 
echo Shutting down
shutdown /s /t 5 /c "Shutting down in 5 seconds"
pause > nul
exit /b 0 

:no 
echo You pressed no! 
pause > nul
exit /b 1

这段代码的缺点是它不与系统时钟同步,因此它变得不同步,而且它在午夜之前也不能用于夜班。

任何帮助改进它都会很棒,不确定如何使用系统时钟作为倒计时的同步变量。

谢谢!

4

1 回答 1

2

前段时间我修改了一个用纯批处理编写的别人的时钟,并给它一个闹钟和定时器,以及几个“皮肤”。这是此类程序的帮助屏幕:

Clock.bat [/D] [/12] [/C] [/S:#] [/B:#] [/T:m[:s]] [/A:hh:mm]

   /D        Set blinking dots
   /12       Set 12 hour format
   /C        Show calendar
   /S:#      Set small size, from 0 to 2 (cancel /Calendar)
   /B:#      Set brightness, from 0 to 3
   /T:m[:s]  Set timer in minutes and optional seconds
   /A:hh:mm  Set alarm time in 24 hour format (minutes in two digits)

You may run several instances of this program to set several timers or alarms
at different times; however, if more than one timer/alarm sounds at same time,
this program may fail.

To stop the buzzing alarm, press Enter.

这是带有计数计时器的 /Size:1 皮肤,以及计时器结束时:

Clock.bat /S:1 定时器运行 Clock.bat /S:1 带定时器嗡嗡声

您可以从本网站下载这样的程序。

于 2014-12-16T20:44:49.280 回答