本帖最后由 buyiyang 于 2024-8-25 12:32 编辑
回复 55# qixiaobin0715
我尝试写了一个- @echo off
- for /f "tokens=2" %%i in ('wmic os get codeset^,localdatetime') do set yyyy=%%i&call set yyyy=%%yyyy:~0,4%%
- set /a _01=_03=_05=_07=_08=_10=_12=31,_04=_06=_09=_11=30,"_02=28+(!(yyyy%%4)&!!(yyyy%%100)|!(yyyy%%400))"
- set "error=echo,Invalid date&endlocal&goto :loop"
-
- :loop
- set /p "md=Please enter a date (M/D):"
- setlocal enabledelayedexpansion
- set "a=!md:*/=!"&set "dd=!a:/=!"
- if "!a!" neq "!dd!" (%error%)
- for /f "delims=0123456789" %%i in ("!md:/=!") do (%error%)
- for /f "tokens=1* delims=/" %%i in ("!md!") do (endlocal&set "mm=%%i"&set "dd=%%j")
- setlocal enabledelayedexpansion
- if "!dd!"=="" (%error%)
- if "!mm:~2,1!" neq "" (%error%)
- if "!dd:~2,1!" neq "" (%error%)
- if "!mm:~0,1!" equ "0" if "!dd:~1,1!"=="" (%error%)
- if "!dd:~0,1!" equ "0" if "!mm:~1,1!"=="" (%error%)
- set "mm=0!mm!"&set "mm=!mm:~-2!"
- set "dd=0!dd!"&set "dd=!dd:~-2!"
- if "!dd!" gtr "00" if "!dd!" leq "!_%mm%!" (echo,Valid date&endlocal&goto :loop)
- %error%
复制代码
|