简体   繁体   English

%TIME%的批次可变范围

[英]Batch Variable Range for %TIME%

For school, I would like to be able to create a batch file that will check what the %TIME% variable is and if it 8:15-9:45 , then goto my first period folder 9:45-10:30 to goto second period, etc. I know how to do this if there is a specific time, but not how to set a range of time. 对于学校,我希望能够创建一个批处理文件,该文件将检查%TIME%变量是什么,如果它是8:15-9:45 ,则转到我的第一个句点文件夹9:45-10:30转到goto我知道如果有特定时间该怎么做,但不知道如何设置时间范围。 Any help would be greatly appreciated! 任何帮助将不胜感激! Thanks. 谢谢。

One way is to convert the time into HHMMSS format. 一种方法是将时间转换为HHMMSS格式。 Something like this 像这样

set timep=%time%
if "%timep:~1,1%" == ":" set timep=0%timep%
set timeval=%timep:~0,2%%timep:~3,2%%timep:~5,2%

Now set the default period to 0 现在将默认期限设置为0

set /a period=0

Since in string form 083000 is between 081500 and 094500, you can just stick to string comparisons without converting to numeric 由于字符串形式083000在081500和094500之间,因此您可以坚持字符串比较而不转换为数字

...
if /i %timeval% geq 103000 set /a period=%period%+1
if /i %timeval% geq 094500 set /a period=%period%+1
if /i %timeval% geq 081500 set /a period=%period%+1

%period% will now hold 0 if the time is less than 0815, 1 if it is between 0815 and 0945 etc. 现在,如果时间小于0815,%period%将保持为0;如果时间在0815和0945之间,则%period%将保持为1,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM