バッチ ファイルのカウントダウン タイマーを作成したいと考えています (制限があるため、バッチ スクリプトにする必要があります)。私はこれまでに 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
このコードの欠点は、システム クロックに同期しないことです。そのため、同期が取れなくなります。また、夜勤の真夜中までは機能しません。
これを改善するための助けは素晴らしいでしょう。システムクロックをカウントダウンの同期変数として使用する方法が本当にわかりません。
ありがとう!