Board logo

标题: [日期时间] 10元求大神 开机检测到时间是某个个时间段就goto [打印本页]

作者: yapda    时间: 2019-11-21 16:15     标题: 10元求大神 开机检测到时间是某个个时间段就goto

应用场景,无盘,开机调用批处理,检测到时间是设定的时间段内就goto,不是就退出
作者: flashercs    时间: 2019-11-21 16:45

本帖最后由 flashercs 于 2019-11-21 18:01 编辑
  1. @echo off
  2. set "起始时间=08:25:39.80"
  3. set "终止时间=19:51:42.00"
  4. set "mytime=%起始时间%"
  5. call :getTod time_1
  6. set "mytime=%终止时间%"
  7. call :getTod time_2
  8. set "mytime=%time%"
  9. call :getTod time_3
  10. set /a "time_dist1=time_2-time_1"
  11. if %time_dist1% LSS 0 set /a "time_dist1+=8640000"
  12. set /a "time_dist2=time_3-time_1"
  13. if %time_dist2% LSS 0 set /a "time_dist2+=8640000"
  14. if %time_dist2% lss %time_dist1% (
  15.   goto label
  16. ) else (
  17.   exit /b
  18. )
  19. :label
  20. echo now is %time%
  21. pause
  22. exit /b
  23. :getTod -- get a Time of Day value in 1/100th seconds
  24. ::   -- %~1: out - time of day
  25. SETLOCAL
  26. set t=%mytime: =0%
  27. set /a t=((1%t:~0,2%*60+1%t:~3,2%)*60+1%t:~6,2%)*100+1%t:~9,2%-36610100
  28. ( ENDLOCAL & REM RETURN VALUES
  29.     IF "%~1" NEQ "" SET %~1=%t%
  30. )
  31. GOTO:EOF
复制代码

作者: zaqmlp    时间: 2019-11-21 17:09

  1. @echo off
  2. set t=08:45-20:02
  3. for /f "tokens=1-4 delims=:." %%a in ("%time: =%") do (set h=00%%a&set m=00%%b)
  4. set now=%h:~-2%:%m:~-2%
  5. echo;%now%
  6. for /f "tokens=1* delims=-" %%a in ("%t%") do (set t1=%%a&set t2=%%b)
  7. if "%t1%" lss "%t2%" (
  8.     if "%now%" geq "%t1%" (
  9.         if "%now%" leq "%t2%" (goto run)
  10.     )
  11. )
  12. if "%t1%" gtr "%t2%" (
  13.     if "%now%" geq "00:00" (
  14.         if "%now%" leq "%t2%" (goto run)
  15.     )
  16.    if "%now%" geq "%t1%" (
  17.         if "%now%" leq "23:59" (goto run)
  18.     )
  19. )
  20. goto end
  21. :run
  22. echo;in
  23. :end
  24. >nul ping /n 3 0
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2