计算一个月内Windows批处理文件中的运行时

时间:2017-09-06 04:23:25

标签: windows batch-file cmd

我目前正在使用%time%来计算多个进程的运行时间。这运行成功运行超过24小时,甚至几天。然而,当在一个月的最后一天执行运行然后在下个月的开始时完成运行时,我得到负面结果。在我尝试自己解决这个问题之前,我希望那里的某个人也遇到这个问题并且有一个修复。

@echo %%time%% = %time%
@FOR /f "tokens=1-2" %%i in ('time /t') do @(
SET EHrMin=%%i
SET Eampm=%%j
)
::
FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Second /Format:table ^| findstr /r "."') DO ( 
set Day=%%A
set Hour=%%B
set Minute=%%C
set Second=%%D 
) 
set Milisecond=%time:~9,2%  
set /a
End=%Day%*8640000+%Hour%*360000+%Minute%*6000+%Second%*100+%Milisecond%
set /a Diff=%End%-%Start%
set /a DiffMS=%Diff%%%100 
set /a Diff=(%Diff%-%DiffMS%)/100 
set /a DiffSec=%Diff%%%60 
set /a Diff=(%Diff%-%Diff%%%60)/60 
set /a DiffMin=%Diff%%%60 
set /a Diff=(%Diff%-%Diff%%%60)/60 
set /a DiffHrs=%Diff%

:: format with leading zeroes 
if %DiffMS% LSS 10 set DiffMS=0%DiffMS!% 
if %DiffSec% LSS 10 set DiffMS=0%DiffSec%
if %DiffMin% LSS 10 set DiffMS=0%DiffMin%
if %DiffHrs% LSS 10 set DiffMS=0%DiffHrs%
cls
echo+
echo    Approximate Model Runtime: %DiffHrs% hours %DiffMin% minutes

screenshot of results

0 个答案:

没有答案