重新计算经过时间的代码:
原文链接:https://www.f2er.com/windows/371610.html>计算代码少,
>提供填充时间少于.1秒,
>使用标签允许多次调用,并对计时器代码进行分组.
可重用代码:
:StartTimer :: Store start time set StartTIME=%TIME% for /f "usebackq tokens=1-4 delims=:.," %%f in (`echo %StartTIME: =0%`) do set /a Start100S=1%%f*360000+1%%g*6000+1%%h*100+1%%i-36610100 goto :EOF :StopTimer :: Get the end time set StopTIME=%TIME% for /f "usebackq tokens=1-4 delims=:.," %%f in (`echo %StopTIME: =0%`) do set /a Stop100S=1%%f*360000+1%%g*6000+1%%h*100+1%%i-36610100 :: Test midnight rollover. If so,add 1 day=8640000 1/100ths secs if %Stop100S% LSS %Start100S% set /a Stop100S+=8640000 set /a TookTime=%Stop100S%-%Start100S% set TookTimePadded=0%TookTime% goto :EOF :DisplayTimerResult :: Show timer start/stop/delta echo Started: %StartTime% echo Stopped: %StopTime% echo Elapsed: %TookTime:~0,-2%.%TookTimePadded:~-2% seconds goto :EOF
通话代码:
call :StartTimer :: :: Add your script functionality here :: call :StopTimer call :DisplayTimerResult pause call :StartTimer :: :: Add more script functionality here :: call :StopTimer call :DisplayTimerResult goto :EOF
注意“1”-prefix,以避免零填充值的解释错误为八进制值(08和09),并用适当的常数进行校正.由于这可能令人困惑的了解核心计算,一行for语句的替代方法将如下所示:
for /f "usebackq tokens=1-4 delims=:.," %%f in (`echo.%StartTIME%`) do set TempTIME=%%f %%g %%h %%i for /f "usebackq tokens=1-4" %%f in (`echo %TempTIME: 0= %`) do set /a Start100S=%%f*360000+%%g*6000+%%h*100+%%i