timecmd.bat 937 B

1234567891011121314151617181920212223242526
  1. @echo off
  2. @setlocal
  3. set start=%time%
  4. :: runs your command
  5. cmd /c %*
  6. set end=%time%
  7. set options="tokens=1-4 delims=:.,"
  8. for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
  9. for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
  10. set /a hours=%end_h%-%start_h%
  11. set /a mins=%end_m%-%start_m%
  12. set /a secs=%end_s%-%start_s%
  13. set /a ms=%end_ms%-%start_ms%
  14. if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
  15. if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
  16. if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
  17. if %hours% lss 0 set /a hours = 24%hours%
  18. if 1%ms% lss 100 set ms=0%ms%
  19. :: mission accomplished
  20. set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
  21. echo command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)