[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[日期时间] 求批处理代码显示实时计算时间

bat依次调用ab.exe计算1.txt,cd.exe 计算2.txt
现在的bat
  1. ab.exe  1.txt
  2. cd.exe  2.txt
复制代码
求代码实时显示ab.exe计算1.txt的用时,cd.exe 计算2.txt的用时
希望的bat
  1. ab.ext  1.txt
  2. 已运行xx小时xx分xx秒
  3. cd.exe  2.txt
  4. 已运行xx小时xx分xx秒
复制代码

  1. @echo off
  2. set "@block={$t=get-date;($t-[datetime][int64]$args[0]).tostring()}"
  3. for /f %%i in ('powershell -c "(get-date).ticks"') do set @time=%%i
  4. ab.exe  1.txt
  5. for /f %%i in ('powershell -c "%@block%.invoke(%@time%)"') do echo 已运行  %%i
  6. for /f %%i in ('powershell -c "(get-date).ticks"') do set @time=%%i
  7. cd.exe  2.txt
  8. for /f %%i in ('powershell -c "%@block%.invoke(%@time%)"') do echo 已运行  %%i
复制代码

TOP

供参考
echo.&echo ===== %folder% 恢复 Printers.请等待 =====
set time_begin=%time:~0,-3%
start /wait /min cmd.exe /c C:\Windows\System32\spool\tools\Printbrm.exe -R -F %folder%
set time_end=%time:~0,-3%
call :_difftime %time_begin% %time_end%
echo Printers 恢复完成. 用时: %hour_% 时 %munite_% 分 %second_% 秒
pause >nul
goto :BackupTools

:_difftime <time_begin> <time_end>
for /f "tokens=1,2,3 delims=:" %%i in ("%time_begin%") do (
    set /a hour_b=%%i
    set /a munite_b=%%j
    set /a second_b=%%k
)
for /f "tokens=1,2,3 delims=:" %%i in ("%time_end%") do (
    set /a hour_a=%%i
    set /a munite_a=%%j
    set /a second_a=%%k
)
if %second_a% lss %second_b% (
    set /a munite_a=%munite_a%-1
    set /a second_a=%second_a%+60
)
set /a second_=%second_a%-%second_b%
if %munite_a% lss %munite_b% (
    set /a hour_a=%hour_a%-1
    set /a munite_a=%munite_a%+60
)
set /a munite_=%munite_a%-%munite_b%

if %hour_a% lss %hour_b% (
    set /a hour_a=%hour_a%+24
)
set /a hour_=%hour_a%-%hour_b%
Goto :eof

TOP

本帖最后由 hnfeng 于 2024-5-31 13:01 编辑

要实时显示,是不是这样的

TOP

返回列表