if %m%==6 if %%a%%4==0 set d=29 错误
call set mon=%%t:~%m%,2%% 没有必要
@echo off&set h=日期313128313031303131303130
for /f "tokens=1,2 delims=-:/ " %%a in ("%date%") do set m=%%b&set y=%%a
if "%m:~0,1%"=="0" set m=%m:~1%
set/a n=%m%*2,r=%y%%%4,m=%m%-1
call set d=%%h:~%n%,2%%
if %m%==2 if %r%==0 set d=29
if %m%==0 set/a y=%y%-1&set m=12
echo %y%年%m%月%d%日&pause
变量%y%为年份,%m%为月份(在set/a m=%m%-1之前,%m%为当前月,之后为上一月),%d%为日期。
%n%为截取用,%r%为判断闰年用的余数。
只有当上一月为0时,才需要计算上一年的年份,并将0改成12。
如果要为月份补前面的0,可以在echo前加上
set m=0%m%
set m=%m:~-2%
或是
if %m% lss 10 set m=0%m%
Last edited by Hanyeguxing on 2010-3-15 at 18:55 ]