本帖最后由 jinzeyu 于 2012-2-29 19:59 编辑
论坛搜索查到一个
http://bbs.bathome.net/thread-11128-1-1.html
但是有些不好理解 自己写了一个- @echo off&setlocal ENABLEDELAYEDEXPANSION
- rem 清空变量
- for /f "delims==" %%a in ('set') do set %%a=
- set /a a1=31,a2=59,a3=90,a4=120,a5=151,a6=181,a7=212,a8=243,a9=273,a10=304,a11=334,a12=365
- set /a b1=31,b2=60,b3=91,b4=121,b5=152,b6=182,b7=213,b8=244,b9=274,b10=305,b11=335,b12=366
- set "start=2007 11 17 14 35 00"
- :main
- set tian=0
- set end=%date:~0,11%%time:~0,8%
- set end=%end:-= %
- set end=%end::= %
- call:handle %start% 1
- call:handle %end% 2
- if "%n1%"=="%n2%" goto equ
- set /a n=%n2%-1
- rem 累加天数
- for /l %%i in (%n1%,1,%n%) do (set /a "tian=tian+(^!(%%i%%4)&^!(^!(%%i%%100))|^!(%%i%%400))+365")
-
- set /a "iii=^!(n1%%4)&^!(^!(n1%%100))|^!(n1%%400)"
- if "%iii%"=="1" (set temp=b) else set temp=a
- set /a tian=%tian%-!%temp%%y1%!-%r1%
- set /a "iii=^!(n2%%4)&^!(^!(n2%%100))|^!(n2%%400)"
- if "%iii%"=="1" (set temp=b) else set temp=a
- set /a tian=%tian%+!%temp%%y2%!+%r2%
- :shuchu
- rem 输出
- set /a shi=%s2%-%s1%
- set /a fen=%f2%-%f1%
- set /a miao=%m2%-%m1%
- if %miao% lss 0 set /a fen-=1&set /a miao+=60
- if %fen% lss 0 set /a shi-=1&set /a fen+=60
- if %shi% lss 0 set /a tian-=1&set /a shi+=24
- cls
- echo %tian%天%shi%时%fen%分%miao%秒
- goto main
-
- :handle 年 月 日 时 分 秒
- set /a n%7=%1,y%7=100%2,r%7=100%3,s%7=100%4,f%7=100%5,m%7=100%6
- set /a y%7=!y%7!%%100
- set /a r%7=!r%7!%%100
- set /a s%7=!s%7!%%100
- set /a f%7=!f%7!%%100
- set /a m%7=!m%7!%%100
- goto:eof
-
- :equ
- set /a "iii=^!(n2%%4)&^!(^!(n2%%100))|^!(n2%%400)"
- set temp=a
- if "%iii%"=="1" set temp=b
- set /a tian=!%temp%%y2%!+%r2%-!%temp%%y1%!-%r1%
- goto shuchu
复制代码 总是差一两天 代码哪里写错了
请帮忙修正 或解释一下这个代码 |