怎么样用批处理计算时间差

我想要实现一个功能就是,先获取当前系统时间,然后运行一个程序(就在批处理里面,比如test.exe <in.txt >out.txt)然后看看这个程序用了多少时间,然后运行另一个程序(类型和之前那个一样),然后比对这两个程序用的时间差是多少,该如何实现呢?
2026年09月23日 06:24
有2个网友回答
网友(1):

你看看这个效果。。值不值0分??呵呵

@echo off& mode con cols=40 lines=10& title 计时
del=tm.txt 2>nul& for %%1 in (1 2)do set x%%1=第%%1个程序正在计时。。。
echo.%x1%
set tm1=%time::=%
rem 在下面输入你要执行的第一个命令
pause
set tm2=%time::=%
call :wind
echo.& echo.
echo.%x2%
set tm1=%time::=%
rem 在下面输入你要执行的第二个命令
pause
set tm2=%time::=%
call :wind
echo.& echo.& set /p tms=for /f "tokens=1-2 delims=-" %%1 in ("%tms%")do echo 第1个命令用时%%1秒 第2个命令用时%%2秒
pause>nul& del=tm.txt& exit
:wind
mshta vbscript:createobject("scripting.filesystemobject").opentextfile("tm.txt",8,true).write(formatnumber(eval(%tm2%-%tm1%),2)^&"-")(window.close)

网友(2):

多给点分啊,不难,但很麻烦...