&&Because of a brother's help request, I suddenly thought of writing a batch script (not using VBS) for arbitrary time backtracking. Because I knew that judging the time points of hours, minutes, days, months, and years would be quite complicated, I was mentally prepared at the beginning, but only when I was in the middle of writing did I really understand the difficulties here. The difficulty lies in how to convert and calculate the arbitrary time entered by others. For example, if you enter 0 0 0 0 100000 (meaning 100,000 minutes), how to convert it into the year, month, day, hour, and minute to backtrack. I racked my brains and still couldn't figure it out clearly. I hope everyone can sort out the ideas. Because the meaning of the problem is also difficult to describe clearly, I specially post my partial code below:
[ Last edited by zw19750516 on 2008-6-2 at 12:39 AM ]
@echo off&color 1f&mode con lines=10&setlocal enabledelayedexpansion
title ***Time Backtracking Batch Script*** by cn-dos zw19750516
:begin
cls&echo.&echo ===============================================================================
echo Please enter the time to backtrack. Please enter it correctly in the format of year month day hour minute. If there is no value, please enter 0. Separate them with spaces in between. Do not pad 0 in front of the value. For example: 10 6 1 19 44 (10 years, 6 months, 1 day, 19 hours, 44 minutes), 0 0 0 0 400 (400 minutes). And 10 06 01 19 44 and 10 6 and 10 6 0 0 0 0 are all incorrect inputs.
echo ===============================================================================
echo.&set /p times=Please enter here:
echo %times: =%|findstr ""&&goto wrong
for %%i in (%times%) do (
set /a n+=1&set str=%%i
if "!str:~,1!" equ "0" goto wrong
)
if !n! neq 5 goto wrong
set n=0
for /f "tokens=1-5 delims= " %%a in ("%times%") do set /a ys=%%a,ms=%%b,ds=%%c,hs=%%d,mis=%%e
set /a y=%date:~,4%,m=100%date:~5,2%%%100,d=100%date:~8,2%%%100,mi=100%time:~3,2%%%100
if "%time:~,1%"=="" (set h=%time:~1,1%) else (set h=%time:~,2%)
set /a a=%y%%%4,b=%y%%%100,c=%y%%%400
if %c% equ 0 (set yun=A) else (if %a% equ 0 if %b% neq 0 set yun=A)
if defined yun (set n=29) else (set n=28)
set /a mi-=mis,h-=hs,d-=ds,m-=ms,h-=hs
............................
:wrong
cls&echo.&echo.&echo Incorrect value. Please enter correctly&ping /n 2 127.1>nul&goto begin
[ Last edited by zw19750516 on 2008-6-2 at 12:39 AM ]
批处理之家新域名:www.bathome.net

