精简获取下一个事件部分:
FOR /F "TOKENS=1,* DELIMS==" %%c IN ('WMIC OS GET /FORMAT:VALUE') DO IF /I "%%c" == "LocalDateTime" SET CurrentDate=%%d
SET CurrentDate=%CurrentDate:~0,8%
SET NextDate=99999999
FOR /F "TOKENS=1,2,3,* DELIMS=. " %%i IN (text2.txt) DO IF %%k%%j%%i GTR %CurrentDate% FOR /F %%r IN ('SET /A NextDate-=%%k%%j%%i') DO IF %%r GTR 0 (
SET NextDate=%%k%%j%%i
SET NextSubject=%%l
)
ECHO The Next test is (%NextDate:~6,2%.%NextDate:~4,2%.%NextDate:~0,4%) and the subject is %NextSubject%.
倒计时器:
这是一个困难的部分。我已经批量完成了日期逻辑(如这里),但它非常耗时。
使用 VBScripting 替代或创建一个小程序来完成这项工作。
编辑:@npocmaka 注意到WMIC
并非所有 Windows 版本的标准,我正在使用 VBS 为这两个部分添加解决方案。
批处理文件:
FOR /F "TOKENS=*" %%d IN ('CSCRIPT /NOLOGO Now.vbs') DO SET CurrentDate=%%d
SET NextDate=99999999
FOR /F "TOKENS=1,2,3,* DELIMS=. " %%i IN (text2.txt) DO IF "%%k %%j %%i" GTR "%CurrentDate%" FOR /F %%r IN ('SET /A NextDate-=%%k%%j%%i') DO IF %%r GTR 0 (
SET NextDate=%%k%%j%%i
SET "NextSubject=%%l"
)
FOR /F "TOKENS=1,2,3,4" %%d IN ('CSCRIPT /NOLOGO DateDiff.vbs %NextDate:~0,4% %NextDate:~4,2% %NextDate:~6,2% 00 00 00 %CurrentDate%') DO ECHO The Next test is %%d days (%NextDate:~6,2%.%NextDate:~4,2%.%NextDate:~0,4%) and the subject is %NextSubject%.
FOR /F "TOKENS=1,2,3,4" %%d IN ('CSCRIPT /NOLOGO DateDiff.vbs %NextDate:~0,4% %NextDate:~4,2% %NextDate:~6,2% 00 00 00 %CurrentDate%') DO ECHO this means it is: %%e hours, %%f minutes, %%g seconds
现在.vbs:
d=Now
WScript.Echo Right("000"&Year(d),4)&" "&Right("0"&Month(d),2)&" "&Right("0"&Day(d),2)&" "&Right("0"&Hour(d),2)&" "&Right("0"&Minute(d),2)&" "&Right("0"&Second(d),2)
日期差异.vbs:
If WScript.Arguments.Count <> 12 Then
WScript.Echo "Syntax: DAYSDIFF yyyy mm dd hh mm ss yyyy mm dd hh mm ss"
Else
d=DateSerial(WScript.Arguments(0),WScript.Arguments(1),WScript.Arguments(2))+TimeSerial(WScript.Arguments(3),WScript.Arguments(4),WScript.Arguments(5))-DateSerial(WScript.Arguments(6),WScript.Arguments(7),WScript.Arguments(8))-TimeSerial(WScript.Arguments(9),WScript.Arguments(10),WScript.Arguments(11))
WScript.Echo Cdbl(Fix(d))&" "&Right("0"&Hour(d),2)&" "&Right("0"&Minute(d),2)&" "&Right("0"&Second(d),2)
End IF