这是通用版,代码多了很多:- @echo off&color 1f&setlocal enabledelayedexpansion
- :begin
- set "days=%date:~,-4%"
- cls&echo.&echo 请在下面输入初始日期(格式为2008-07-08,默认为当天)
- echo.&set /p days=^=^>
- if "%days:~4,1%%days:~7,1%" neq "--" echo.&echo 请正确输入&ping /n 2 127.1>nul&goto begin
- set /p str=<1.txt
- for %%i in (%str%) do if "%%i" equ "开始时间" set /a num+=1
- cls&set /p=电视台 日期 开始时间 节目名称<nul>2.txt
- for /l %%i in (2,1,%num%) do set /p= 时长 日期 开始时间 节目名称
- <nul>>2.txt
- echo.>>2.txt
- for /f "skip=1 delims=" %%a in (1.txt) do (
- for %%i in (%%a) do (
- set /a n+=1&if !n! equ 3 set "n=1"
- if !n! equ 2 (
- set /a x+=1
- set /a y=x-1
- set "_!x!=%%i"&call :lp
- ) else (
- set /p=%%i <nul>>2.txt
- )
- )
- echo.>>2.txt&set "_!x!="&set "x=0"&set "n=0"
- )
- start 2.txt&goto :eof
- :lp
- for /f "tokens=1-2 delims=:" %%i in ("!_%y%!") do set "s1=%%i"&set "m1=%%j"
- for /f "tokens=1-2 delims=:" %%i in ("!_%x%!") do set "s2=%%i"&set "m2=%%j"
- set /a s=100%s2%%%100-100%s1%%%100,m=100%m2%%%100-100%m1%%%100
- set /a year=%days:~,4%,month=100%days:~5,2%%%100,day=100%days:~-2%%%100
- if %m% lss 0 set /a m+=60,s-=1
- if %s% lss 0 (
- if %x% neq 1 set /a s+=24,day=100%day%%%100+1
- call :judge
- )
- for %%i in (%month% %day%) do if %%i lss 10 set "%%i=0%%i"
- set /a num=60*s+m,v=0
- if %x% neq 1 (
- set /p=%num% %year%-%month%-%day% !_%x%! <nul>>2.txt
- ) else (
- set /p=%year%-%month%-%day% !_%x%! <nul>>2.txt
- )
- goto :eof
- :judge
- set /a ys1=year%%4,ys2=year%%100,ys3=year%%400
- set "py=28"
- if %ys2% neq 0 (
- if %ys1% equ 0 set "py=29"
- ) else (
- if %ys3% equ 0 set "py=29"
- )
- for %%i in (31 %py% 31 30 31 30 31 31 30 31 30 31) do set /a v+=1&set ".!v!=%%i"
- if %day% gtr !.%month%! set /a day=1,month+=1
- if %month% gtr 12 set /a month=1,year+=1
复制代码
ps:" "不是空格是制表符
[ 本帖最后由 batman 于 2008-7-29 23:22 编辑 ] |