2014-09-24 73 views
0

下面的代碼顯示只有小時的時間值:mm格式,我所要的輸出是HH:MM。任何人都可以確定在哪裏添加什麼。 以下是我的輸入文件。 我也在底部添加了putput。下面如何打印時間HH:MM格式下面的代碼


@ECHO OFF 
ECHO Task calculation 


set /P st=Please enter the CRQ Start time(hh:mm) 


set calc1=00:30 
set calc2=01:00 
set calc3=01:00 
set calc4=00:30 


set task1=st 



set /A centis=(1%st:~0,2%-100)*3600+(1%st:~3,2%-100)*60 
if %centis% GTR 86400 set centis=0 
set /A c1=(%calc1:~0,2%)*3600+(%calc1:~3,2%)*60 
set /A c2=(%calc2:~0,2%)*3600+(%calc2:~3,2%)*60 
set /A c3=(%calc3:~0,2%)*3600+(%calc3:~3,2%)*60 
set /A c4=(%calc4:~0,2%)*3600+(%calc4:~3,2%)*60 


set /a t1=centis+c1 
if %t1% GTR 86400 set t1=0 
set /a t1h=t1/3600 
set /a t1m=(t1-(t1h*3600))/60 


set /a t2=t1+c2 
if %t2% GTR 86400 set t2=0 
set /a t2h=t2/3600 
set /a t2m=(t2-(t2h*3600))/60 


set /a t3=t2+c3 
if %t3% GTR 86400 set t3=0 
set /a t3h=t3/3600 
set /a t3m=(t3-(t3h*3600))/60 


set /a t4=t3+c4 
if %t4% GTR 86400 set t4=0 
set /a t4h=t4/3600 
set /a t4m=(t4-(t4h*3600))/60 



echo. 
echo TASK1 StartTime :%st% 
echo. 
echo Task1 EndTime :%t1h%:%t1m% 
echo. 


echo Task2 StartTime :%t1h%:%t1m% 
echo. 
echo Task2 EndTime :%t2h%:%t2m% 
echo. 


echo Task3 StartTime :%t2h%:%t2m% 
echo. 
echo Task3 EndTime :%t3h%:%t3m% 
echo. 


echo Task4 StartTime :%t3h%:%t3m% 
echo. 
echo Task4 EndTime :%t4h%:%t4m% 
echo. 


echo CRQ EndTime :%t4h%:%t4m% 
echo. 


pause>null 

輸出:

Task calculation 
Please enter the CRQ Start time(hh:mm)07:00 

TASK1 StartTime :07:00 

Task1 EndTime :7:30 

Task2 StartTime :7:30 

Task2 EndTime :8:30 

Task3 StartTime :8:30 

Task3 EndTime :9:30 

Task4 StartTime :9:30 

Task4 EndTime :10:0 

CRQ EndTime :10:0 
+2

'if%tXh%lss 10 set tXh = 0%tXh%'所有時間。 – npocmaka 2014-09-24 12:17:56

+0

Thankx這個作品:) – 2014-09-24 14:21:34

回答

0

npocmaka已經回答了這個問題。

這裏是爲仍然含有的塊插入前導0對於所有輸出的小時和分鐘最後由批處理文件輸出這個問題與完整批次碼的回答。在處理它們之前,用戶輸入的小時和分鐘仍未被評估。

@ECHO OFF 
ECHO Task calculation 

set /P "st=Please enter the CRQ start time [hh:mm]: " 

set calc1=00:30 
set calc2=01:00 
set calc3=01:00 
set calc4=00:30 

set /A centis=(1%st:~0,2%-100)*3600+(1%st:~3,2%-100)*60 
if %centis% GTR 86400 set centis=0 
set /A c1=(%calc1:~0,2%)*3600+(%calc1:~3,2%)*60 
set /A c2=(%calc2:~0,2%)*3600+(%calc2:~3,2%)*60 
set /A c3=(%calc3:~0,2%)*3600+(%calc3:~3,2%)*60 
set /A c4=(%calc4:~0,2%)*3600+(%calc4:~3,2%)*60 

set /a t1=centis+c1 
if %t1% GTR 86400 set t1=0 
set /a t1h=t1/3600 
set /a t1m=(t1-(t1h*3600))/60 

set /a t2=t1+c2 
if %t2% GTR 86400 set t2=0 
set /a t2h=t2/3600 
set /a t2m=(t2-(t2h*3600))/60 

set /a t3=t2+c3 
if %t3% GTR 86400 set t3=0 
set /a t3h=t3/3600 
set /a t3m=(t3-(t3h*3600))/60 

set /a t4=t3+c4 
if %t4% GTR 86400 set t4=0 
set /a t4h=t4/3600 
set /a t4m=(t4-(t4h*3600))/60 

if %t1h% lss 10 set t1h=0%t1h% 
if %t2h% lss 10 set t2h=0%t2h% 
if %t3h% lss 10 set t3h=0%t3h% 
if %t4h% lss 10 set t4h=0%t4h% 
if %t1m% lss 10 set t1m=0%t1m% 
if %t2m% lss 10 set t2m=0%t2m% 
if %t3m% lss 10 set t3m=0%t3m% 
if %t4m% lss 10 set t4m=0%t4m% 

echo. 
echo Task1 StartTime: %st% 
echo. 
echo Task1 EndTime: %t1h%:%t1m% 
echo. 

echo Task2 StartTime: %t1h%:%t1m% 
echo. 
echo Task2 EndTime: %t2h%:%t2m% 
echo. 

echo Task3 StartTime: %t2h%:%t2m% 
echo. 
echo Task3 EndTime: %t3h%:%t3m% 
echo. 

echo Task4 StartTime: %t3h%:%t3m% 
echo. 
echo Task4 EndTime: %t4h%:%t4m% 
echo. 

echo CRQ EndTime:  %t4h%:%t4m% 
echo. 

pause >nul