Windows bat 当前、昨天、明天日期

当前日期

echo %date% #输出2020/07/15 周三
echo %date:~0,10% #2020/07/15
echo %date:~0,4%%date:~5,2%%date:~8,2% #20200715
echo %time% # 9:09:39.92

昨天日期

yesterday.bat

@echo off
echo Wscript.echo dateadd("d",-1,date)>vbs.vbs
for /f %%a in ('cscript /nologo vbs.vbs') do del vbs.vbs&&set yyyymmdd=%%a
for /f "tokens=1,2,3* delims=// " %%i in ('echo %yyyymmdd%') do set yyyy=%%i&set mm=%%j&set dd=%%k
if   %mm%   LSS   9   set   mm=0%mm%
if   %dd%   LSS   9   set   dd=0%dd%
set yesterday=%yyyy%-%mm%-%dd%
echo 昨天是:%yesterday%
echo 请按任意键退出
pause>nul

明天日期

tomorrow.bat

@echo off
echo Wscript.echo dateadd("d",1,date)>vbs.vbs
for /f %%a in ('cscript /nologo vbs.vbs') do del vbs.vbs&&set yyyymmdd=%%a
for /f "tokens=1,2,3* delims=// " %%i in ('echo %yyyymmdd%') do set yyyy=%%i&set mm=%%j&set dd=%%k
if   %mm%   LSS   9   set   mm=0%mm%
if   %dd%   LSS   9   set   dd=0%dd%
set tomorrow=%yyyy%-%mm%-%dd%
echo 明天是:%tomorrow%
echo 请按任意键退出
pause>nul

你可能感兴趣的:(Windows bat 当前、昨天、明天日期)