我在做一个自动更新系统,如果软件一定天数没有更新,我需要系统打开一个网页。我记录了每次自动更新的日期,因此我需要帮助的只是获取上次自动更新与当前日期之间的天数。我希望你也能提供有关你的代码的解释,非常感谢你的努力,提前致谢。
这里有一个使用 VBS 的解决方案
@echo off
set "from=01-01-2001"
set "to=12-19-2011"
echo Wscript.Echo #%to%# - #%from%# >tmp.vbs
for /f %%a in ('cscript /nologo tmp.vbs') do set "total=%%a"
del tmp.vbs
echo The Total number of days from %from% until %to% is %total%
我把这个藏起来了:
:: Using Powershell
:: Count the number of days from %1 to %2
:: date format is yyyy/mm/dd
@echo off
set from=2001/01/01
set to=2011/12/19
if not "%~1"=="" set from=%1
if not "%~2"=="" set to=%2
set /a a1=%from:~0,4% + 1
set /a a2=%to:~0,4% - 1
if %from:~0,4% EQU %to:~0,4% (
set "sameyear=(get-date %to%).dayofyear - "
) else (
set "sameyear=(get-date %from:~0,4%/12/31).dayofyear - "
)
>file.ps1 echo Set-ExecutionPolicy unrestricted
>>file.ps1 echo $a=%sameyear%(get-date %from%).dayofyear
for /L %%a in (%a1%, 1, %a2%) do (
>>file.ps1 echo $a=$a + (get-date %%a/12/31^).dayofyear
)
if NOT %from:~0,4% EQU %to:~0,4% (
>>file.ps1 echo $a=$a + (get-date %to%^).dayofyear
)
>>file.ps1 echo.echo $a
for /f "delims=" %%a in (
'powershell -file file.ps1'
) do set total=%%a
del file.ps1 2>nul
echo The Total number of days from %from% until %to% is %total%
你可能也想尝试这样的事情。
set/p searchdate= Enter search date (ddmmyyyy):