我有一个批处理脚本,它执行几个 Python 脚本,然后需要安排最后一个 Python 脚本在 9000 秒后执行。以下是我目前的情况:(我只知道如何手动设置时间)
C:\> schtasks /create /tn StockRelease /tr D:\dev\autopilot\check_reservation_timeouts.py /sc once /st 10:14
成功:计划任务“StockRelease”已成功创建。
我的问题是,如何计算 9000 秒后是什么时间?
我确信这个问题已经在某个地方得到解答了,但我很可能用了错误的关键字进行搜索。我检查了 Microsoft 文档https://technet.microsoft.com/en-us/library/cc772785(v=ws.10).aspx以及各种超级用户问题。
答案1
直接从满足相同要求的某人的页面上获取,我复制并粘贴了以下代码:
::============================================
::GET THE CURRENT HOUR AND MINUTE + 10 MINUTES
::============================================
SET CURRENTTIME=%TIME%
for /F "tokens=1 delims=:" %%h in ('echo %CURRENTTIME%') do (set /a HR=%%h)
for /F "tokens=2 delims=:" %%m in ('echo %CURRENTTIME%') do (set /a MIN=%%m + 10)
::=======================================================
::IF THE MINUTE IS >= 60, ROLL IT OVER BY SUBSTRACTING 60
::FROM MINUTES AND ADDING 1 TO HOURS
::=======================================================
IF %MIN% GEQ 60 (
SET /a MIN=%MIN%-60
SET /a HR=%HR%+1
)
::===========================================================================
::IF THE HOUR IS > 24, THEN IT IS BECAUSE WE ADDED 1 TO 24 ABOVE. SET IT TO 0
::===========================================================================
IF %HR% GTR 24 SET HR=00
::============================================
::PAD SINGLE DIGIT MINUTES WITH A LEADING ZERO
::============================================
IF %MIN% LEQ 9 (
SET MIN=0%MIN%
)
::==========================================
::PAD SINGLE DIGIT HOURS WITH A LEADING ZERO
::==========================================
IF %HR% LEQ 9 (
SET HR=0%HR%
)
::========================================================================
::USE THE NEW HOUR AND MINUTE (AND EXISTING SECONDS) TO CREATE THE NEW TIME
::========================================================================
SET NEWTIME=%HR%:%MIN%:%CURRENTTIME:~6,10%
来源:http://acoderslife.com/index.cfm/blog/Adding-XX-minutes-to-the-current-time-in-a-Windows-batch-file
您需要根据自己的需求定制其余部分 - 即,将计划任务设置为一次性任务,这样当您不需要时它就不会重复。我还会写入您的脚本 [在计划任务执行时执行] 以删除计划任务,这样您就不会填满计划任务管理器。