[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
纯批处理延时
示例:
1. 延时 10 秒:
  1. call :Slepp1d  10
复制代码
2. 延时23小时:
  1. call :Slepp1d  82800
复制代码
注意:不支持超过一天的延时(应小于86400秒)

代码如下
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. call :Slepp1d 10
  4. pause
  5. goto :eof
  6. :: Call :Slepp1d_loop 5
  7. goto :eof
  8. :Slepp1d
  9.   if not defined time_start (
  10.     set/a n_sleep=%~1
  11.     set time_start=%time%
  12.     call :Slepp1d_Count !time_start!
  13.     if not defined n_star set/a n_star=!dt1c!
  14.   )
  15.   call :Slepp1d_count %time%
  16.   set/a n_now=%dt1c%
  17.   set/a n_check=%n_star% + %n_sleep% - %n_now%
  18.   if %n_check% geq 0 (
  19.     if "%n_check%" neq "%n_check_last%" echo %n_check% %hns%
  20.     set n_check_last=%n_check%
  21.     ping -w 500 -n 2 0.0.0.0 >nul
  22.     goto :Slepp1d
  23.   )
  24.   goto :eof
  25. :Slepp1d_Count
  26.   set dt1=%~1
  27.   for /f "delims=: tokens=1,2,3*" %%i in ("%dt1%") do (
  28.     set dt1h=%%i
  29.     if "!dt1h:~0,1!"=="0" set/a dt1h=!dt1h:~1,1!
  30.     set dt1n=%%j
  31.     if "!dt1n:~0,1!"=="0" set/a dt1n=!dt1n:~1,1!
  32.     set dt1s=%%k
  33.     set dt1s=!dt1s:~0,2!
  34.     if "!dt1s:~0,1!"=="0" set/a dt1s=!dt1s:~1,1!
  35.   )
  36.   set "hns=%dt1h%:%dt1n%:%dt1s%"
  37.   set/a dt1c=(%dt1h% * 60 * 60) + (%dt1n% * 60) + (%dt1s%)
  38.   set/a dt1c=%dt1c% %% (60 * 60 * 24)
  39.   goto :eof
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

返回列表