- ::明天日期
- @echo off
- setLocal enableDelayedExpansion
-
- ::今天日期变数字
- set "today=%date:~0,4%%date:~5,2%%date:~8,2%"
- call :date2num today nday
- echo 日期 %today% 对应数字 %nday%
- ::pause
- ::goto :eof
- ::
-
- ::明天数字变日期
- call :num2date nday+1 tomorrow
- echo 数字 %nday%+1 对应日期 %tomorrow%
-
- cd/d%~dp0
- md %tomorrow%
-
- pause
- goto :eof
- ::====
-
-
- ::计算日期的天号。参数YYYYMMDD,输出num
- :date2num formatdate index
- setlocal
- set "fdate=!%1!"
- set/a y=1%fdate:~,4%-10000,m=1%fdate:~4,2%-100,d=1%fdate:~6,2%-100
- set/a y1=y-1,m3=(m-1)*3
- set/a "leap=^!(y%%4)&^!^!(y%%100)|^!(y%%400)",T2=28+leap
- set Mdays=+31+T2+31+30+31+30+31+31+30+31+30+31
- set/a days=d!Mdays:~,%m3%!
- set/a nday=y1/4-y1/100+y1/400+y1*365+days
- endlocal&set %2=%nday%
- goto :eof
-
- ::计算数字对应的日期。参数num,输出YYYYMMDD;调用函数Lyear数字是否超过一年及闰年
- :num2date num fdate
- setlocal
- set/a n=%1,year=1,y=n/366 %_估年_%
- set/a ny=(y/4-y/100+y/400)+y*365,y+=year,n-=ny
- :iyear 精算年份。 //多出的天一年一年加入
- call :Lyear n y flag leap
- if %flag%==0 goto :mday
- set/a y+=flag,n-=365+leap
- goto :iyear
- :mday 计算几月几日。 //leap在最后一次调用:Lyear函数时得出
- set/a T2=28+leap,m=1,d=n
- set Mdays=+31+T2+31+30+31+30+31+31+30+31+30+31
- for /l %%m in (36,-3,3)do (
- set/a days=0!Mdays:~,%%m!
- if %n% gtr !days! set/a m+=%%m/3,d=n-days&goto :outfor
- )
- :outfor
- set/a fy=10000+y,fm=100+m,fd=100+d
- set fdate=%fy:~-4%!fm:~-2!%fd:~-2%
- endlocal&set %2=%fdate%
- goto :eof
-
- ::根据数字年号判断是否加一年及闰年
- :Lyear num year flagYearAdd leap
- setlocal
- set/a n=%1,y=%2
- set/a "leap=^!^!(y%%100)&^!(y%%4)|^!(y%%400)"
- set/a Ydays=365+leap,fy=0
- if %n% gtr %Ydays% set fy=1
- endlocal&set %3=%fy%&set %4=%leap%
- goto :eof
复制代码
|