- @echo on
- setlocal enabledelayedexpansion
- set curr_year=%date:~0,4%
- set curr_month=%date:~5,2%
- set curr_day=%date:~8,2%
-
- if %curr_month:~0,1%==0 set curr_month=%curr_month:~1,1%
- if %curr_day:~0,1%==0 set curr_day=%curr_day:~1,1%
-
- set last_year=%curr_year%
- set tmp_last_month=%curr_month%
- set /a tmp_last_day=%curr_day%-1
-
- if %tmp_last_day%==0 set /a tmp_last_month=%curr_month%-1
-
- if !tmp_last_day!==0 (
- if !tmp_last_month!==0 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==1 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==2 (
- goto leap_year
- )
- if !tmp_last_month!==3 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==4 (
- set last_day=30
- goto final
- )
- if !tmp_last_month!==5 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==6 (
- set last_day=30
- goto final
- )
- if !tmp_last_month!==7 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==8 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==9 (
- set last_day=30
- goto final
- )
- if !tmp_last_month!==10 (
- set last_day=31
- goto final
- )
- if !tmp_last_month!==11 (
- set last_day=30
- goto final
- )
- ) else (goto :final)
-
- :leap_year
- set leapyear_flag=0
- set /a isleapyear=%curr_year%%%4
- if %isleapyear%==0 set leapyear_flag=1
- set /a isleapyear=%curr_year%%%400
- if %isleapyear%==0 set leapyear_flag=1
- set /a isleapyear=%curr_year%%%100
- if %isleapyear%==0 set leapyear_flag=0
- set tmp_last_day=28
- if %leapyear_flag%==1 set tmp_last_day=29
-
-
- :final
- if %tmp_last_month%==0 (
- set /a last_year=%curr_year%-1
- set last_month=12
- )
-
- set last_month=%temp_last_month%
- if %tmp_last_month%==1 set last_month=01
- if %tmp_last_month%==2 set last_month=02
- if %tmp_last_month%==3 set last_month=03
- if %tmp_last_month%==4 set last_month=04
- if %tmp_last_month%==5 set last_month=05
- if %tmp_last_month%==6 set last_month=06
- if %tmp_last_month%==7 set last_month=07
- if %tmp_last_month%==8 set last_month=08
- if %tmp_last_month%==9 set last_month=09
-
- set last_day=%tmp_last_day%
- if %tmp_last_day%==1 set last_day=01
- if %tmp_last_day%==2 set last_day=02
- if %tmp_last_day%==3 set last_day=03
- if %tmp_last_day%==4 set last_day=04
- if %tmp_last_day%==5 set last_day=05
- if %tmp_last_day%==6 set last_day=06
- if %tmp_last_day%==7 set last_day=07
- if %tmp_last_day%==8 set last_day=08
- if %tmp_last_day%==9 set last_day=09
-
- set dt=%last_year:~0,4%-%last_month:~0,2%-%last_day:~0,2%
-
- md d:\%dt%
复制代码 每次都执行到 leap_year, 帮忙看看是哪里的问题? |