批处理计算时间

作者: 禾白小三飘 | 来源:发表于2016-01-07 15:53 被阅读56次

批处理计算时间的方法

@echo off & setlocal enabledelayedexpansion
set app=notepad.exe
tasklist |find "%app%"||start %app%
set hh=1%time:~0,2% & set /a mm=1%time:~3,2% + 3
if %mm% GTR 159 (set /a mm =%mm% - 60 & set /a hh=%hh%+1)
if %hh% GTR 123 set hh=100
set ten=%hh:~1,2%:%mm:~1,2%
set now=%time:~0,5%
:0
cls
echo 如果现在时间%time:~0,5%等于%ten%将结束进程%app%
:1
if %time:~0,5% == %ten% (taskkill /f /im notepad.exe & exit)
if %time:~0,5% GTR %now% (set now=%time:~0,5% & goto :0)
ping -n 3 127.0.0.1 >nul
goto :1

思路:
通过计算出10分钟后的时间,再与现在时间比较。

TIMEOUT命令直接搞定

set app=notepad.exe
timeout /t 600
taskkill /f /im %app%

等待600秒后,杀掉记书本进程。

相关文章

网友评论

    本文标题:批处理计算时间

    本文链接:https://www.haomeiwen.com/subject/tsyfkttx.html