有些人可能知道我一直在批量重制时钟,这几乎完成了,但我知道我意识到我的计时器脚本不太有效。 我遇到的问题是计时器何时结束,或者当我只输入 1 分钟时,它会变成 -1 天 23 小时...有人可以告诉我如何执行类似于我的代码的操作吗?我见过其他代码,但它们有固定的时间,并且没有我的代码具有的
2 seconds
然后1 second
功能。
感谢一路上给予我帮助的大家,真的很感激!
@echo off
setlocal EnableExtensions EnableDelayedExpansion
:menu
cls
echo Instructions:
echo.
echo Select the amount of time you like.
echo Type "0" to not include that variable. e.g. Hours: 0
echo Would not include hours in the timer.
echo.
pause
goto input-days
:input-days
cls
set /p "days=How many days?: "
if not defined days goto input-days
goto input-hours
:input-hours
cls
set /p "hours=How many hours?: "
if not defined hours goto input-hours
goto input-minutes
:input-minutes
cls
set /p "minutes=How many minutes?: "
if not defined minutes goto input-minutes
goto input-seconds
:input-seconds
cls
set /p "seconds=How many seconds?: "
if not defined seconds goto input-seconds
goto check-seconds
:check-seconds
if %seconds% geq 60 (
set /a minutes+=1
set /a seconds-=1
)
goto check-minutes
:check-minutes
if %seconds% geq 60 (
goto check-seconds
)
if %minutes% geq 60 (
set /a hours+=1
set /a minutes-=1
)
goto check-hours
:check-hours
if %minutes% geq 60 (
goto check-minutes
)
if %hours% gtr 24 (
set /a days+=1
set /a hours-=24
)
goto noTextCursor-timer
:noTextCursor-timer
For /f %%e in ('Echo Prompt $E^|cmd') Do set "\E=%%e"
<nul Set /P "=%\E%[?25l"
Set /A "delay=4", "Files=0","FC=1"
For %%i in (5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5)Do (
Set /A Files+=1
Call :timer %%i "infile!Files!.txt"
)
For /L %%i in ()Do (
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1"
if !tDiff! lss 0 set /a tDiff+=24*60*60*100
if !tDiff! geq !delay! (
Set /A "FC=FC %% Files + 1"
<nul Set /P "=%\E%[1;0H"
If !FC! GTR 10 (If !Offset! GTR 1 Set /A "Offset-=1")Else Set "offset=!FC!"
(For /f "Delims=" %%G in (infile!FC!.txt)Do echo ^[[K%\E%[!offset!G%%G%\E%[E") > Con
echo ^[[0J
set /a t1=t2
)
)
:timer
<nul set /p "=%\E%[H"
if "%days%"=="1" (
set "dayAmount=day"
) else (
set "dayAmount=days"
)
if "%hours%"=="1" (
set "hourAmount=hour"
) else (
set "hourAmount=Hours"
)
if "%minutes%"=="1" (
set "minuteAmount=minute"
) else (
set "minuteAmount=minutes"
)
if "%seconds%"=="1" (
set "secondAmount=second"
) else (
set "secondAmount=seconds"
)
echo Timer: %days% %dayAmount%, %hours% %hourAmount%, %minutes% %minuteAmount%, ^& %seconds% %secondAmount% remaining.
timeout /t 1 /nobreak >nul
set /a seconds-=1
if %seconds% leq 0 (
set /a minutes-=1
set seconds=59
)
if %minutes% leq 0 (
set /a hours-=1
set minutes=59
)
if %hours% leq 0 (
set /a days-=1
set hours=23
)
set check=seconds+minutes+hours+days
if %check% leq 0 (
goto end
)
goto timer
:end
cls
echo The timer is finished!
pause
@echo off
setlocal EnableExtensions EnableDelayedExpansion
:menu
cls
echo Instructions:
echo.
echo Select the amount of time you would like.
echo Type "0" to not include that variable. e.g., Hours: 0
echo Would not include hours in the timer.
echo.
pause
goto input-days
:input-days
cls
set /p "days=How many days?: "
if "!days!"=="" set days=0
goto input-hours
:input-hours
cls
set /p "hours=How many hours?: "
if "!hours!"=="" set hours=0
goto input-minutes
:input-minutes
cls
set /p "minutes=How many minutes?: "
if "!minutes!"=="" set minutes=0
goto input-seconds
:input-seconds
cls
set /p "seconds=How many seconds?: "
if "!seconds!"=="" set seconds=0
goto start-timer
:start-timer
set /a total_seconds=(((days*24 + hours)*60 + minutes)*60 + seconds)
:timer-loop
if %total_seconds% leq 0 goto end
set /a days=total_seconds / 86400
set /a hours=(total_seconds %% 86400) / 3600
set /a minutes=((total_seconds %% 86400) %% 3600) / 60
set /a seconds=((total_seconds %% 86400) %% 3600) %% 60
cls
echo Timer: %days% days, %hours% hours, %minutes% minutes, & %seconds% seconds remaining.
timeout /t 1 /nobreak >nul
set /a total_seconds-=1
goto timer-loop
:end
cls
echo The timer is finished!
pause