本帖最后由 neorobin 于 2012-4-2 02:34 编辑
- @echo off & setlocal enabledelayedexpansion
- set /a "wid=6, cols=wid*7" & mode con lines=13 cols=!cols!
- for /l %%i in (1 1 !wid!) do for /l %%j in (1 1 7) do set "sps= !sps!"
- for %%w in (!wid!) do (
- REM for %%a in (S M T W T F S) do set "w=!sps!%%a" & set "weekTitle=!weekTitle!!w:~-%%w!"
- for %%a in (日 一 二 三 四 五 六) do set "w=!sps!%%a " & set "weekTitle=!weekTitle!!w:~-%%w,-1!"
- set "ds32=!sps!" & for /l %%i in (1 1 32) do set "d=!sps!%%i"&set "ds32=!ds32!!d:~-%%w!"
- )
- call :today
- :doCom
- set /a "y=ys, ms=(ms-1)%%12+1, m=ms, mf=ms+100"
- set /a "p=y-1+400,m-=1,d1=1,di=d1+y*365+1-97+p/4-p/100+p/400+m*31+(~(m-4)>>31)+(~(m-6)>>31)+(~(m-9)>>31)+(~(m-11)>>31)+((~(m-2)>>31)&-2-(^!^!(y&3)|(^!^!(y&0xf)&^!0x!y:~-2!)))"
- set /a "wk=(di+5)%%7, wk+=(wk>>31)&7, pos=(7-wk)*wid+2" & rem (di+5)%%7 取正余数方能得到对应的星期值
- set /a "m=ms,trunc=wid*(-1-(^!(m-4)|^!(m-6)|^!(m-9)|^!(m-11))-^!(m-2)*(3-(^!(y&3)&^!^!(y%%100)|^!(y%%400))))"
- cls & title !y!.!m!& <nul set /p "=!weekTitle:~2!!sps:~-2!!sps: =-!"
- if "!today: 0= !"=="!ys! !ms! !d!" for %%d in (!d!) do set "ds32=!ds32: %%d =★%%d !"
- for /f "tokens=1-2" %%p in ("!pos! !trunc!") do (echo !ds32:~%%p,%%q!!sps:~-%%p!!sps:~%%q!)& set "ds32=!ds32:★= !"
- set "com=." &echo,&echo,!sps:~-16!!today!&set /p "com=-[W] !ys! [S]+!sps:~-16!-[A] !mf:~1! [D]+[SPACE] to today: "
- for /l %%i in (0 1 100) do (
- if "!com:~%%i,1!"=="" goto :doCom
- if /i "!com:~%%i,1!"=="W" set /a "ys-=1"
- if /i "!com:~%%i,1!"=="S" set /a "ys+=1"
- if /i "!com:~%%i,1!"=="A" set /a "ms-=1, ys-=^!ms, ms+=(ms-1>>31)&12"
- if /i "!com:~%%i,1!"=="D" set /a "ms+=1, ys+=^!(ms-13), ms-=(12-ms>>31)&12"
- if /i "!com:~%%i,1!"==" " call :today
- echo !com!|findstr "^[0-9]" && for /f "tokens=1-2" %%a in ("!com!") do set /a "ys=%%a,ms=%%b"&goto :doCom
- )
- goto :doCom
- exit
-
- :today
- for /f "tokens=2*" %%a in ('reg query "HKCU\Control Panel\International" /v sShortDate^|find/i"sSh"') do (
- >nul reg add "HKCU\Control Panel\International" /v sShortDate /t REG_SZ /d "yyyy MM dd" /f
- set /a "ys=!date:~0,4!,ms=1!date:~5,2!-100,d=1!date:~-2!-100" & set "today=!date!"
- >nul reg add "HKCU\Control Panel\International" /v sShortDate /t REG_SZ /d "%%~b" /f
- )
- exit /b
复制代码 W, S 键切换年份, A, D 键切换月份, 空格键 回到当前月份; 也可直接输入年和月(请用空格分隔): yyyy m. 例如: 2000 8
支持查询直到公元 0 年(尽管公元纪年的起点是公元1年, 并沒有「公元0年」), 代码不足 40 行, 没有农历及别的功能. |