本帖最后由 abcdshenji 于 2011-5-29 18:37 编辑
- @echo off||检查日期合法性(yyyymmdd)
- :top
- cls
- set /p dt=Enter date:
- echo %dt%|findstr "^[0-9]*$">nul||(call :lp "日期只能是数字")
- if %dt% gtr 10000000 (
- if %dt% lss 30000000 (ver>nul) else (
- call :lp "只能是3000年以内"
- )
- ) else (
- call :lp "不足1000年"
- )
- set/a y=%dt%/10000,m=%dt%%%10000/100,d=%dt%%%100
- set "ds=312831303130313130313031"
- for /l %%i in (1 1 12) do (
- if %m% equ %%i (
- set /a n=%m%*2
- setlocal enabledelayedexpansion
- set n=!n:~-2!
- endlocal
- )
- )
- if %d% gtr 0 (
- if %d% leq %n% (call :lp "合法") else (
- call :lp "%m%月没有%d%天"
- )
- ) else call :lp "天数不能是0"
- pause>nul&goto :top
- :lp
- echo %~1&pause>nul&goto :top
- goto :EOF
复制代码 没有进行平润年判断。。。这么多if else没什么效率可言就是了。。凑合着看吧。。 |