China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 17:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Give up, do not enter]About backtracking to any time View 2,267 Replies 32
Floor 16 Posted 2008-06-01 23:22 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by moniuming at 2008-6-1 23:19:

I think the LZ means: 20 years + 2 months + 600 days + 4000 hours + 10000 minutes

But it feels meaningless, and even............. Alas

It's not meaningless. The motivation for me to write this batch script is to make it convenient for everyone to trace back time.
批处理之家新域名:www.bathome.net
Floor 17 Posted 2008-06-01 23:23 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
20 years 2 months 600 days 4000 hours 10000 minutes
Let's put it this way
Subtract 10000 minutes from the current time first, then subtract 4000 hours, then subtract 600 days.
Suppose the result at this time is March 20, 2005, 19:20. Then how to subtract 2 months at this time?
Is the result January 20, 2005, 19:20?
致精致简!
Floor 18 Posted 2008-06-01 23:26 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
If it's just like this, it's still manageable to estimate. The following is for calculating the number of days. It should be no problem to add handling for hours and minutes.

@echo off
SET/p TT=你想知道多少天前的日期?
for /f "tokens=1-3 delims=-/\:. " %%i in ("%date%") do set /a p1=%%i,p2=100%%j%%100,p3=100%%k%%100
if %p3% gtr %TT% goto ppp
:nxt
set/a p2-=1
if %p2% equ 0 set/a p1-=1&&set p2=12
set/a PN2="!(p1%%4) & !(!(p1%%100)) | !(p1%%400)",PN2=28+PN2
for /f "tokens=%p2%" %%i in ("31 %pN2% 31 30 31 30 31 31 30 31 30 31") do set/a p3=%p3%+%%i
if %p3% leq %tt% goto nxt
:ppp
set/a p3=%p3%-%tt%
setlocal enabledelayedexpansion
for %%i in (p2 p3) do if !%%i! lss 10 set %%i=0!%%i!
echo %p1%年%p2%月%p3%日
pause&goto :eof
简单!简单!再简单!
Floor 19 Posted 2008-06-01 23:28 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by 26933062 at 2008-6-1 23:23:
20 years 2 months 600 days 4000 hours 10000 minutes
Let me put it this way
First subtract 10,000 minutes from the current time, then subtract 4,000 hours, then subtract 600 days,
Assuming the result at this time is March 20, 2005 19:20, then this...

Brother, your thinking is deviated. In the end, there will not be exactly two months subtracted. Instead, you should convert and calculate the previous ones first, then decrement from minutes all the way to years

[ Last edited by zw19750516 on 2008-6-1 at 11:30 PM ]
批处理之家新域名:www.bathome.net
Floor 20 Posted 2008-06-01 23:36 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by terse at 2008-6-1 23:26:
If it's just like this, it's estimated to be manageable.
The following is to calculate the number of days. Adding the processing of hours and minutes should be no problem.

@echo off
SET/p TT=你想知道多少天前的日期?
for /f "tokens=1-3 delim ...

Dude, you should still remember the few posts I made before about date calculation. Please believe that I have no problem with such algorithms. What I need to solve now is the problem of converting any time.
批处理之家新域名:www.bathome.net
Floor 21 Posted 2008-06-01 23:45 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Originally posted by zw19750516 at 2008-6-1 23:36:

Dude, you should still remember a few threads I posted before about date calculations, right? Please believe that I'm okay with such algorithms. What I need to solve now is the problem of converting arbitrary times.

How exactly is it converting arbitrary times? I'm a bit slow-witted, hope you can explain it to me.
简单!简单!再简单!
Floor 22 Posted 2008-06-01 23:53 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by terse at 2008-6-1 23:45:

How to convert any time? I'm sorry I'm stupid, please brother explain it to me.

Oh, I've discussed this for such a long time before, but brother still doesn't understand what I mean. It's also my fault for not explaining clearly.
For example, when entering 20 38 67 900 30000 at the batch processing prompt for time backtracking, going back 20 years + 38 months + 67 days + 900 hours + 30000 minutes from the current time is? years? months? days? hours? minutes.
First, convert minutes to whole hours a + remainder, then convert hours + a to whole months b + remainder (here is stuck), then convert months + b to whole years c + remainder, then add years + c, and then I can't think clearly...

[ Last edited by zw19750516 on 2008-6-1 at 11:59 PM ]
批处理之家新域名:www.bathome.net
Floor 23 Posted 2008-06-01 23:55 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
I really can't understand the problem. For 20 years or 2 months, there must always be a specific number of days! Then there must be the phenomenon I mentioned on the 17th floor.
致精致简!
Floor 24 Posted 2008-06-02 00:03 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by 26933062 at 2008-6-1 23:55:
I really can't understand the problem.
For 20 years or 2 months, there must be a specific number of days. Then there must be the phenomenon I mentioned on floor 17.

The number of days is definitely there. On the time coordinate, the point in time that goes back 20 years + 39 months + 470 days + 6000 hours + 10001 minutes from the current time must exist. The problem is how we can find this point in time. This will involve a series of judgments and conversion calculations.
ps: Brother, won't you also think I'm an alien, hehe.

[ Last edited by zw19750516 on 2008-6-2 at 12:05 AM ]
批处理之家新域名:www.bathome.net
Floor 25 Posted 2008-06-02 00:17 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
So it seems that there should be a reason for the order, because there are intercalary months, isn't that right?
简单!简单!再简单!
Floor 26 Posted 2008-06-02 00:21 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by terse at 2008-6-2 00:17:
In this case, there should be a rule for the order. Because there is a leap month, right?

It's said that the order is minute-hour-day-month-year. It's so difficult because of the problem of leap months and the different number of days in each month!!!
批处理之家新域名:www.bathome.net
Floor 27 Posted 2008-06-02 00:24 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Okay, let's do this step by step. First, the current time is April 2, 2008, 20:10. We need to go back 2 months, 1 day, 1 hour, and 1 minute.

First, subtract 2 months from April 2008. April minus 2 months is February 2008. But wait, we need to be careful with the days. February 2008 has 29 days because 2008 is a leap year.

Now, start with April 2, 20:10. Subtract 1 day first: April 2, 20:10 minus 1 day is March 31, 20:10. Then subtract 2 months from March 31, 20:10. March minus 2 months is January 31, 20:10. Now subtract 1 hour: January 31, 20:10 minus 1 hour is January 31, 19:10. Then subtract 1 minute: January 31, 19:10 minus 1 minute is January 31, 19:09. Wait, no, that's not right. Wait, I made a mistake. Let's start over.

Current date: April 2, 2008, 20:10.

Step 1: Subtract 2 months. April - 2 months = February. But February 2008 has 29 days. So April 2 - 2 months = February 2, 20:10. Then subtract 1 day: February 2 - 1 day = January 31, 20:10. Then subtract 1 hour: January 31, 20:10 - 1 hour = January 31, 19:10. Then subtract 1 minute: January 31, 19:10 - 1 minute = January 31, 19:09. Wait, that can't be right. Wait, I messed up the month subtraction. Let's do it properly.

Current date: 2008-04-02 20:10:00

Subtract 2 months: 2008-04-02 minus 2 months is 2008-02-02 20:10:00

Then subtract 1 day: 2008-02-02 minus 1 day is 2008-02-01 20:10:00

Then subtract 1 hour: 2008-02-01 20:10:00 minus 1 hour is 2008-02-01 19:10:00

Then subtract 1 minute: 2008-02-01 19:10:00 minus 1 minute is 2008-02-01 19:09:00

Wait, no, I made a mistake here. Wait, April minus 2 months is February, but February 2008 has 29 days. So April 2nd minus 2 months is February 2nd. Then February 2nd minus 1 day is January 31st. Then January 31st 20:10 minus 1 hour is January 31st 19:10, minus 1 minute is January 31st 19:09. But wait, let's check again.

Wait, let's use a different approach. Let's convert the current time to total minutes since a certain point, then subtract the total minutes for 2 months, 1 day, 1 hour, 1 minute, then convert back.

Current time: April 2, 2008, 20:10. Let's calculate total minutes from, say, January 1, 2000, but that's complicated. Alternatively, calculate day by day.

April has 30 days, March has 31, February 2008 has 29, January has 31.

Current date: April 2, 2008. So from January 1, 2008 to April 2, 2008: January has 31 days, February 29, March 31, April 2. Total days: 31 + 29 + 31 + 2 = 93 days. Total minutes: 93 days * 24 hours/day * 60 minutes/hour + 20 hours * 60 + 10 = 93*1440 + 1200 + 10 = 133920 + 1210 = 135130 minutes.

Now, we need to subtract 2 months, 1 day, 1 hour, 1 minute.

2 months: Let's take January and February. January has 31 days, February 29. So 2 months is 31 + 29 = 60 days. Then subtract 1 day: 60 - 1 = 59 days. Then subtract 1 hour: 59 days is 59*24 = 1416 hours, minus 1 hour is 1415 hours. Then subtract 1 minute: 1415 hours is 1415*60 = 84900 minutes, minus 1 minute is 84899 minutes.

Now, subtract 84899 minutes from 135130 minutes: 135130 - 84899 = 50231 minutes.

Now, convert 50231 minutes back to days, hours, minutes.

50231 minutes / (24*60) = 50231 / 1440 = 34 days with a remainder. 34*1440 = 48960. 50231 - 48960 = 1271 minutes.

1271 minutes / 60 = 21 hours with a remainder. 21*60 = 1260. 1271 - 1260 = 11 minutes.

Now, find the date. Starting from January 1, 2008, add 34 days. January has 31 days, so 34 days from January 1 is January 1 + 34 days = February 4? Wait, no. Wait, I made a mistake in the direction. Wait, we subtracted time, so we need to go back.

Wait, I think I messed up the total minutes calculation. Let's start over correctly.

Current date and time: 2008-04-02 20:10:00

We need to subtract 2 months, 1 day, 1 hour, 1 minute.

Step 1: Subtract 2 months. April - 2 months = February. So date becomes 2008-02-02 20:10:00

Step 2: Subtract 1 day. 2008-02-02 - 1 day = 2008-02-01 20:10:00

Step 3: Subtract 1 hour. 2008-02-01 20:10:00 - 1 hour = 2008-02-01 19:10:00

Step 4: Subtract 1 minute. 2008-02-01 19:10:00 - 1 minute = 2008-02-01 19:09:00

Wait, but let's check with another method. Let's use months with 30 days for simplicity, but adjust for leap years.

April 2, 20:10 minus 2 months is February 2, 20:10. Then February 2 minus 1 day is January 31, 20:10. Then January 31, 20:10 minus 1 hour is January 31, 19:10. Then January 31, 19:10 minus 1 minute is January 31, 19:09. Hmm, but wait, February 2008 has 29 days, so April 2 minus 2 months is February 2, which is correct. Then February 2 minus 1 day is January 31, correct. Then January 31, 20:10 minus 1 hour is 19:10, minus 1 minute is 19:09. So the result should be January 31, 2008, 19:09.Wait, no, I think I made a mistake in the month subtraction. Let's do it month by month correctly.

Current month: April. Subtract 2 months: April - 2 = February. So the date is February 2, 20:10. Then subtract 1 day: February 2 - 1 = January 31, 20:10. Then subtract 1 hour: January 31, 20:10 - 1 = January 31, 19:10. Then subtract 1 minute: January 31, 19:10 - 1 = January 31, 19:09. Yes, that's correct. So the time 2 months, 1 day, 1 hour, 1 minute before April 2, 2008 20:10 is January 31, 2008 19:09.
致精致简!
Floor 28 Posted 2008-06-02 00:30 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
9:19 on January 1, 2008, this is easy to calculate, but the following is not easy:
20:10 on April 20, 2008 minus 2 months, 48 days, 29 hours, 78 minutes
批处理之家新域名:www.bathome.net
Floor 29 Posted 2008-06-02 00:37 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Forget it, maybe I really overcomplicated things (in fact, there's no such thing as 39 months, 500 days, 6,000 hours, 10,00able minutes like 20 years ago). I have to work tomorrow, so I'll go to sleep first. Thanks, brothers.
批处理之家新域名:www.bathome.net
Floor 30 Posted 2008-06-02 00:43 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Originally posted by zw19750516 at 2008-6-2 00:30:
9 minutes 19 hours 1 day February 2008, this is easy to calculate, but the following is not easy to calculate:


[ Last edited by zw19750516 on 2008-6-2 at 12:31 AM ]

Is this not just subtracting 2 full months?
First subtract the minutes, hours, days, and the result is: 9 minutes 19 hours April 1, 2008
Then subtract 2 full months, that is: 4 minus 2 gives 9 minutes 19 hours February 1, 2008
致精致简!
Forum Jump: