计算 100 年的日期 耗时 3.7 秒- @echo off&setlocal enabledelayedexpansion
- set t=%time%
- echo 请输入8位数的起始日期和结束日期用空格分开
- echo 或只输入结束(开始)日期,默认当前日期为起始(结束)日期
- echo 输入格式 20080205 21080529&echo.
- set xx=19100201
- for /f "tokens=1,2" %%i in ("%xx%") do (
- if not "%%j"=="" (set qs=%%i&set js=%%j) else (
- for /f "tokens=1-3 delims=.\-/ " %%a in ("!date!") do (
- if %%a%%b%%c gtr %%i (set/a qs=xx,js=%%a%%b%%c) else (
- set/a qs=%%a%%b%%c,js=%%i
- ))))
- for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do set/a n+=1&set/a yue!n!=%%a
- set /a qsd=100%qs:~4,2%%%100,qsm=100%qs:~6,2%%%100
- set /a yuq=qsd,yuh=12,mq=qsm,mh=yue!qsd!
- (
- echo 起始日期 %qs:~0,4%-%qs:~4,2%-%qs:~6,2%
- echo 结束日期 %js:~0,4%-%js:~4,2%-%js:~6,2%
- for /l %%i in (%qs:~0,4% 1 %js:~0,4%) do (
- if %%i equ %js:~0,4% set /a yuh=100%js:~4,2%%%100&set flag=a
- for /l %%j in (!yuq! 1 !yuh!) do (
- if %%j equ 2 (
- set /a yue2="^!(%%i%%4)&^!(^!(%%i%%100))|^!(%%i%%400)"+28,mh=yue2
- ) else set /a mh=yue%%j
- if defined flag if %%j equ !yuh! set /a mh=100!js:~-2!%%100
- for /l %%k in (!mq! 1 !mh!) do (
- set numd=0%%j&set "numm=0%%k"
- echo %%i!numd:~-2!!numm:~-2!
- )
- set /a mq=1&echo;
- )
- set yuq=1
- )
- echo 耗时:
- echo %t%
- echo !time!
- )>c.txt
- start c.txt
- exit
复制代码
[ 本帖最后由 FOR 于 2010-4-7 23:22 编辑 ] |