:year_set_daye
set/p year_set_daye=输入4位年份 [回车]退出:
if "%year_set_daye%" =="" goto :eof
echo.%year_set_daye%|findstr "\<[1-9][0-9][0-9][0-9]\>" >nul&&goto month_set_daye||echo 输入4位年份(只能是0-9,首位不能为0)&goto year_set_daye
:month_set_daye
set/p month_set_daye=输入月份 [回车]退出:
if "%month_set_daye%" == "" echo 不能为空&goto month_set_daye
echo.%month_set_daye%|findstr "\<[0-1][0-9]\>" >nul&&(goto month_next)||(echo 输入2位月份&goto month_set_daye)
:month_next
if %month_set_daye% gtr 12 echo.输入月份大于了12&goto month_set_daye
if "%month_set_daye%" lss "01" echo.错误输入&goto month_set_daye
echo %month_set_daye%|findstr "^[0-9]*$">nul&&goto day_set_daye||echo 只能是0-9&goto month_set_daye
:day_set_daye
set/p p3=输入日期 [回车]退出:
if "%p3%" == "" echo 不能为空 &goto day_set_daye
echo.%p3%|findstr "\<[0-3][0-9]\>" >nul&&(goto day_next)||(echo 输入2位日期&goto day_set_daye)
:day_next
if %p3% gtr 31 echo.错误输入&goto day_set_daye
if %p3% lss 1 echo.错误输入&goto day_set_daye
echo %p3%|findstr "^[0-9]*$">nul&&goto p4||echo 只能是0-9&goto day_set_daye
:p4
....
...
@echo off&setlocal enabledelayedexpansion
set msn= 31 28 31 30 31 30 31 31 30 31 30 31
set ms0= 31 29 31 30 31 30 31 31 30 31 30 31
:lp
set /p gd=输入开始日期(yyyy-mm-dd):
set gd=%gd:~0,10%
if not "%gd:~4,1%%gd:~7,1%"=="--" goto :err
set/a d=1%gd:~8,2%-100,m=1%gd:~5,2%-100,y=1%gd:~0,4%-10000 || goto :err
if %y% lss 1800 goto :err
if %y% gtr 2050 goto :err
if %m% gtr 12 goto :err
if %m% leq 0 goto :err
if %d% leq 0 goto :err
set/a vy=y%%4,vm=^(m+11^)%%12*3
if %vy%==0 (set ms=%ms0%) else (set ms=%msn%)
set am=!ms:~%vm%,3!
if %d% gtr %am% goto :err
::前面校验日期的有效性,并把年,月,日分别存到变量y,m,d
set ch=7
::计算七天后日期
set/a d+=ch
if %d% gtr %am% (set/a m+=1
if !m! gtr 12 (set/a y+=1,m=1)
set/a d-=am
)
::调整日期格式
if %m% lss 10 (set m=0%m%)
if %d% lss 10 (set d=0%d%)
set date-x=%y%-%m%-%d%
echo 输入的日期是:%gd%
echo 该日期%ch%天后是:%date-x%
echo.
echo.
::修改文件数据
(echo =============================================
for /f "tokens=1* delims==" %%a in (a.property) do (
if "%%b"=="" (echo.%%a) else (
set "str=%%a"
if "!str:~0,9!"=="BeginDate" (echo.%%a=%gd%)
if "!str:~0,7!"=="EndDate" (echo.%%a=%date-x%)
if "!str:~0,6!"=="Minute" (echo.%%a=%%b)
)
)
echo =============================================)>a.temp
type a.temp>a.property
type a.temp&del a.temp
pause
goto :eof
:err
echo 输入格式有错!请重新输入.&goto :lp
if 1%month_set_daye% lss 101 echo.错误输入&goto month_set_daye
@echo off
set /p month_set_daye=请输入月份:
if 1%month_set_daye% lss 101 (
echo.错误输入
goto :month_set_daye
)
echo 行。
goto :eof
:month_set_daye
echo 不行?去电线杆上找老中医!
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Test>test.bat 请输入月份:08 行。 C:\Test>test.bat 请输入月份:09 行。 C:\Test>test.bat 请输入月份:0 错误输入 不行?去电线杆上找老中医! C:\Test>[/olor]