?? 計(jì)算花費(fèi)的時(shí)間.bat
字號(hào):
@echo off
:: 判斷一個(gè)腳本執(zhí)行完畢所需要的時(shí)間
:: 先取開(kāi)始時(shí)間,然后在即將結(jié)束的時(shí)候取結(jié)束時(shí)間
:: 兩個(gè)時(shí)間都分別提取小時(shí)、分和秒數(shù)
:: 分別對(duì)小時(shí)數(shù)、分鐘數(shù)和秒數(shù)進(jìn)行操作
:: 還要對(duì)08和09這兩個(gè)數(shù)進(jìn)行操作
:: 注意:set /a num=的格式只能處理兩位數(shù)中是否高位為0,如果是多位數(shù)
:: 要去高位的所有0的話,要用循環(huán)測(cè)試高位是否為0或者在高位添1然后
:: 再減去1000之類的數(shù)字的方法
:: code by JM 2006-9-5~10 CMD@XP 感謝pengfei測(cè)試
set time_begin=%time:~0,-3%
echo 腳本開(kāi)始運(yùn)行時(shí)間是 %time_begin%
:: 小于10的小時(shí)數(shù)前有空格,要做去空格操作
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
)
pause
set time_end=%time:~0,-3%
for /f "tokens=1,2,3 delims=:" %%i in ("%time_end%") do (
set /a hour_e=%%i
set /a munite_e=%%j
set /a second_e=%%k
)
call :time_lapse
echo 腳本結(jié)束運(yùn)行的時(shí)間是 %time_end%
echo 共花費(fèi)了 %hour_% 小時(shí) %munite_% 分 %second_% 秒
pause>nul
goto :eof
:time_lapse
:: 一定要按照 秒=>分鐘=>小時(shí) 的順序操作
if %second_e% lss %second_b% (
set /a munite_e=%munite_e%-1
set /a second_e=%second_e%+60
)
set /a second_=%second_e%-%second_b%
if %munite_e% lss %munite_b% (
set /a hour_e=%hour_e%-1
set /a munite_e=%munite_e%+60
)
set /a munite_=%munite_e%-%munite_b%
if %hour_e% lss %hour_b% (
set /a hour_e=%hour_e%+24
)
set /a hour_=%hour_e%-%hour_b%
goto :eof
另外一種方法(Code by Pengfei):
@echo off
::11:08:25.45
:: 運(yùn)行程序的時(shí)間統(tǒng)計(jì)
set _time_start=%time%
set /a hour_start=%_time_start:~0,2%
set /a minute_start=1%_time_start:~3,2%-100
set /a second_start=1%_time_start:~6,2%-100
echo %time%
echo %hour_start%
echo %minute_start%
echo %second_start%
pause
:: 結(jié)束程序的時(shí)間統(tǒng)計(jì)
set _time_end=%time%
set /a hour_end=%_time_end:~0,2%
set /a minute_end=1%_time_end:~3,2%-100
set /a second_end=1%_time_end:~6,2%-100
echo %time%
echo %hour_end%
echo %minute_end%
echo %second_end%
pause
:: 計(jì)算秒數(shù)
if %second_end% lss %second_start% (
set /a second_end=%second_end%+60
set /a minute_end=%minute_end%-1
)
set /a second=%second_end%-%second_start%
:: 計(jì)算分鐘數(shù)
if %minute_end% lss %minute_start% (
set /a minute_end=%minute_end%+60
set /a hour_end=%hour_end%-1
)
set /a minute=%minute_end%-%minute_start%
:: 計(jì)算小時(shí)數(shù)
if %hour_end% lss %hour_start% (
set /a hour_end=%hour_end%+24
)
set /a hour=%hour_end%-%hour_start%
echo %hour%:%minute%:%second%
pause
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -