写了几个通用函数- @echo off & cd /d ""%~dp0
- setlocal enabledelayedexpansion
-
- :: 设置起始年份和结束年份
- set START_YEAR=2024
- set END_YEAR=2024
-
- :: 设置起始月份和结束月份
- set START_MONTH=11
- set END_MONTH=12
-
- for /l %%y in (%START_YEAR%, 1, %END_YEAR%) do (
- for /l %%m in (%START_MONTH%, 1, %END_MONTH%) do (
- call :get_monthday %%y %%m
- set "END_DAY=!_RET_!"
- for /l %%d in (1,1,!END_DAY!) do (
- call :get_weekday %%y %%m %%d
- echo %%y-%%m-%%d week!_RET_!
- rem 跳过周六周日
- if not !_RET_!==6 if not !_RET_!==7 (
- echo mkdir %%y\%%y-%%m\%%y-%%m-%%d
- mkdir %%y\%%y-%%m\%%y-%%m-%%d >nul 2>nul
- )
- echo -------------------------
- )
- )
- )
-
- pause&exit
-
- rem 获取某一天是星期几 _RET_[1-7]:get_weekday(year,month,day)
- :get_weekday
- call :get_days %1 %2 %3
- set /a "_RET_=%_RET_%%%7"
- if,%_RET_%==0 set "_RET_=7"
- goto :eof
-
- rem 获取总天数 _RET_:get_days(year,month,day)
- :get_days
- set /a "y=%1-1"
- set /a "y1=%y%/4-%y%/100+%y%/400"
- set /a "m1=0,m2=m1+31"
- call :check_r %1 && (set /a m3=m2+29) || (set /a m3=m2+28)
- set /a "m4=m3+31,m5=m4+30,m6=m5+31,m7=m6+30,m8=m7+31,m9=m8+31,m10=m9+30,m11=m10+31,m12=m11+30,m13=m12+31"
- call set /a "_RET_=%y%*365+%y1%+%%m%2%%+%3"
- goto :eof
-
- rem 获取某年里某个月有几天 _RET_[28-31]:get_monthday(year,month)
- :get_monthday
- set /a "m1=31"
- call :check_r %1 && (set /a m2=29) || (set /a m2=28)
- set /a "m3=31,m4=30,m5=31,m6=30,m7=31,m8=31,m9=30,m10=31,m11=30,m12=31"
- call set "_RET_=%%m%2%%"
- goto :eof
-
- rem 判断闰年 BOOL:check_r(year)
- :check_r
- set /a "1/(%1%%400)" >nul 2>nul || (exit /b 0)
- set /a "1/(%1%%100)" >nul 2>nul && (set /a "1/(%1%%4)" >nul 2>nul && (exit /b 1) || (exit /b 0) ) || (exit /b 1)
- goto :eof
复制代码
|