我正在使用批处理脚本来测量命令的时间。我在 StackOverflow 上找到了这个脚本。不幸的是,它有时无法正常工作,不幸的是我对批处理编程知之甚少。我的印象是它有时有效,有时无效。也许我在这方面犯了错误,但它似乎在午夜后无法正常工作。
剧本:
@echo off
setlocal
rem The format of %TIME% is HH:MM:SS,CS for example 23:59:59,99
set STARTTIME=%TIME%
rem here begins the command you want to measure
dir /s > nul
rem here ends the command you want to measure
set ENDTIME=%TIME%
echo STARTTIME %STARTTIME%
rem convert STARTTIME and ENDTIME to centiseconds
set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)
echo STARTTIME %STARTTIME%
echo ENDTIME %ENDTIME%
set /A ENDTIME=(1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100)
echo ENDTIME %ENDTIME%
rem calculating the duration is easy
set /A DURATION=%ENDTIME%-%STARTTIME%
rem we might have measured the time inbetween days
if %ENDTIME% LSS %STARTTIME% set set /A DURATION=%STARTTIME%-%ENDTIME%
rem outputing
echo DURATION: %DURATION% in centiseconds
endlocal
goto :EOF
我半小时前正在使用它,我得到了这个结果:
STARTTIME 1:29:25.17
STARTTIME 1:29:25.17
ENDTIME 1:29:27.82
ENDTIME 1:29:27.82
DURATION: 1 in centiseconds
所以有线条的东西
set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)
和
线
set /A ENDTIME=(1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100)
似乎是错误的。
它是什么?
问候,大卫