- @echo off
- set mydate=2012-02-02
- call :DateToOrdinal %mydate:~0,4% %mydate:~5,2% %mydate:~8,2% year doy
- call :DateToWeek %mydate:~0,4% %mydate:~5,2% %mydate:~8,2% yn cw dw
- echo %mydate%是%year%年的第%doy%天,第%cw%周。
- pause
- goto :eof
-
- :DateToOrdinal %yy% %mm% %dd% year doy
- setlocal ENABLEEXTENSIONS
- set yy=%1&set mm=%2&set dd=%3
- if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
- set /a dd=100%dd%%%100,mm=100%mm%%%100
- set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
- set /a j=j/5+dd+y*365+y/4-y/100+y/400-32045
- set /a y=yy+4799,k=y*365+y/4-y/100+y/400-31738,o=j-k+1
- if %o% LSS 100 set o=0%o%&if %o% LSS 10 set o=00%o%
- endlocal&set %4=%yy%&set %5=%o%&goto :EOF
-
- :DateToWeek %yy% %mm% %dd% yn cw dw
- setlocal ENABLEEXTENSIONS
- set yy=%1&set mm=%2&set dd=%3
- if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
- set /a dd=100%dd%%%100,mm=100%mm%%%100
- set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,Jd=153*m+2
- set /a Jd=Jd/5+dd+y*365+y/4-y/100+y/400-32045
- set /a y=yy+4798,Jp=y*365+y/4-y/100+y/400-31738,t=Jp+3,Jp=t-t%%7
- set /a y=yy+4799,Jt=y*365+y/4-y/100+y/400-31738,t=Jt+3,Jt=t-t%%7
- set /a y=yy+4800,Jn=y*365+y/4-y/100+y/400-31738,t=Jn+3,Jn=t-t%%7
- set /a Jr=%Jp%,yn=yy-1,yn+=Jd/Jt,yn+=Jd/Jn
- if %Jd% GEQ %Jn% (set /a Jr=%Jn%) else (if %Jd% GEQ %Jt% set /a Jr=%Jt%)
- set /a diff=Jd-Jr,cw=diff/7+1,wd=diff%%7,wd+=1
- if %cw% LSS 10 set cw=0%cw%
- endlocal&set %4=%yn%&set %5=%cw%&set %6=%wd%&goto :EOF
复制代码
|