输入08和09的代码崩溃了

时间:2014-08-31 14:19:12

标签: batch-file

当我尝试运行以下代码并将开始时间设为08:00或09:00时,它会立即崩溃。甚至像08:45,09:45等等的值都不起作用。

有人可以帮我解决问题所在。 提前谢谢。


@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=(%st:~0,2%)*3600+(%st:~3,2%)*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 TASK1 StartTime :%st%
echo Task1 EndTime :%t1h%:%t1m%


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


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


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


echo CRQ EndTime :%t4h%:%t4m%


pause>null

1 个答案:

答案 0 :(得分:5)

在批处理文件中,以0开头的数字是八进制格式,因此08不是有效值

set /A centis=(1%st:~0,2%-100)*3600+(1%st:~3,2%-100)*60

在两位数字之前包含1(即+100)和aditional -100解决问题