Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
1.8 kB
3
Indexable
Never
@echo off &:: NTP_time_diff.bat by penknife
setlocal EnableDelayedExpansion
set "_a="
rem set /p "_a=test: +secs: " & call :td %time:~0,8% !_a! &set "_a=!_time.f!"
for /l %%n in (1,1,5) do if not defined _a for /f "tokens=1-10 delims=:. " %%a in ('w32tm /stripchart /computer:tempus2.gum.gov.pl /samples:1') do if /i "%%~d"=="d" echo [%%n]%%a:%%b:%%c %%d:%%e.%%f %%g:%%h.%%i & call :td %%a:%%b:%%c %%h & set "_a=!_time.f!"
rem jeśli powyższe zapytanie (do 5 prób) wykona się poprawnie zapisze stosowną wartość w zmiennej _a i przejdzie dalej
echo.
if defined _a ( echo %_a% ) else echo 	Error:incorrect data
for %%# in (%CmdCmdLine%) do if /i "%%~#"=="/c" echo.&pause
endlocal & set "_Current_time=%_a%"
goto :eof
:td
if "%~2"=="" set "_time.f=" &goto :eof
for %%# in ("+00" "-00") do if "%~2"=="%%~#" set "_time.f=%~1" &goto :eof
setlocal EnableDelayedExpansion
set "_t.diff=%2"
set "_t.f=%1"
set "_t.h=%_t.f:~0,2%"
set "_t.m=%_t.f:~3,2%"
set "_t.s=%_t.f:~6,2%"
set "_t.f="
if "%_t.diff:~1,1%"=="0" set "_t.diff=%_t.diff:~0,1%%_t.diff:~2%"
for %%a in (h m s) do (
if "!_t.%%a:~0,1!"=="0" set "_t.%%a=!_t.%%a:~1!"
if "!_t.%%a!"=="" set "_t.%%a=0"
set "_t.%%a=!_t.%%a::=!"
)
set /a "_t.d=60*60*24,_t.div=60,_t.diff=%_t.diff%"
set /a "_t.dif=%_t.diff%/%_t.d%"
set /a "_t.diff=%_t.diff%%%_t.d%"
if %_t.diff% lss 0 set /a "_t.s+=%_t.d%,_t.dif-=1"
set /a "_t.c=%_t.s% +%_t.diff% +60*(%_t.m%+60*%_t.h%)"
set /a "_t.dif+=%_t.c%/%_t.d%"
set /a "_t.c=(%_t.c%)%%(%_t.d%)"
set /a "_t.s=(%_t.c%)%%_t.div%"
set /a "_t.m=(%_t.c%/%_t.div%)%%_t.div%"
set /a "_t.h=%_t.c%/(%_t.div%*%_t.div%)"
for %%a in (h m s) do if !_t.%%a! lss 10 set "_t.%%a=0!_t.%%a!"
if "%_t.dif%" neq "0" echo  Warning: different day(s): %_t.dif% >&2
set "_t.f=%_t.h%:%_t.m%:%_t.s%"
endlocal & set "_time.f=%_t.f%"
rem echo.&echo Current time: %_time.f%
goto :eof
Leave a Comment