|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『楼 主』:
[已放弃请勿进]关于对任意时间的回溯
使用 LLM 解释/回答一下
&&因一个兄弟的求助贴,突然想到写一个任意时间回溯的批处理(非vbs),因为
知道要对分时日月年进行判断相当复杂,开始也做好了思想准备,可写到中间才
真正明白此中的难处,难就难在怎么把别人输入的任意时间进行转换计算,如输
入0 0 0 0 100000(指100000分钟),怎么把之转代成要回溯的年月日时分,我
脑壳想破了也没想清楚,望大家帮理一下思路,因问题的意思也难以描述清楚,
特在下面贴出我的部分代码:
@echo off&color 1f&mode con lines=10&setlocal enabledelayedexpansion
title ***时间回溯批处理*** by cn-dos zw19750516
:begin
cls&echo.&echo ===============================================================================
echo 请输入要回溯的时间,请按年 月 日 时 分的格式正确输入,无数值的请输入0,中间请用空格格开,请不要在数值前补0,如:10 6 1 19 44(10年6个月1天19个小时44分钟),0 0 0 0 400(400分钟),而10 06 01 19 44和10 6以及10 6 0 0 0 0均为错误输入。
echo ===============================================================================
echo.&set /p times=请在此输入:
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 错误的数值,请正确输入&ping /n 2 127.1>nul&goto begin
Last edited by zw19750516 on 2008-6-2 at 12:39 AM ]
&&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:
@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 |
|
2008-6-1 21:58 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
|
2008-6-1 22:17 |
|
|
plp626
银牌会员
     钻石会员
积分 2278
发帖 1020
注册 2007-11-19
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
我对次类问题的算法就是:先把任意给定的日期转换为分钟数(根据需要还可转为秒数,小时,天数),再将分钟数转换为日前,
可以参看函数库里的函数---timediff
My algorithm for this kind of problem is: first convert any given date into minutes (and if needed, also convert to seconds, hours, days), and then convert the minutes back into a date. You can refer to the functions in the function library --- timediff
|

山外有山,人外有人;低调做人,努力做事。
进入网盘(各种工具)~~ 空间~~cmd学习 |
|
2008-6-1 22:20 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
其实对天数的回溯,论坛早有经典代码了。
只要对时间部分判断一下天数就可以了。
In fact, there are classic codes in the forum for backtracking days. Just judge the number of days in the time part.
|

致精致简! |
|
2008-6-1 22:23 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
兄弟们是不是想简单了啊,论坛相关的贴子我都看了的,还在qq上和namejm讨论了。
Brothers, is it too simple? I've read all the forum-related posts and also discussed with namejm on QQ.
|

批处理之家新域名:www.bathome.net |
|
2008-6-1 22:28 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
其实的我的本意是写一个任意时间回溯批处理出来,别人只要按年 月 日 时 分的输入格式输入的任一组五个数值就能得到回溯后是?年?月?日?时?分,如输入0 0 0 100000 0(100000小时)。
In fact, my original intention was to write a batch processing program for arbitrary time backtracking. As long as others input any set of five values in the input format of year, month, day, hour, and minute, they can get the backtracked year, month, day, hour, and minute. For example, input 0 0 0 100000 0 (100000 hours).
|

批处理之家新域名:www.bathome.net |
|
2008-6-1 22:32 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
要求 zw19750516 兄公布自己的QQ号码和 namejm 的QQ号码^_^
Request zw19750516 brother to disclose his QQ number and namejm's QQ number ^_^
|

 |
|
2008-6-1 22:35 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
提供个思路
先把 月 、日、时间、转换成天数。
再用当前年减去输入的年、
再用结果减去转换的天数、最后在精确一下时间。
Provide an idea: First, convert the month, day, and time into the number of days. Then subtract the input year from the current year. Then subtract the converted number of days from the result. Finally, refine the time precisely.
|

致精致简! |
|
2008-6-1 22:37 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2008-6-1 22:37:
提供个思路
先把 月 、日、时间、转换成天数。
再用当前年减去输入的年、
再用结果减去转换的天数、最后在精确一下时间。
谢谢兄弟多次关注,请看这组数值20 34 600 4000 10000,回溯20年34个月600天4000个小时10000分钟,我有个思路就是把系统当前时间到公元元年元月元日零时零分的时间差以分为计数单位算出来,然后将输入的所有时间转为以分计数的值,再将系统值减去输入转换值,再从基准值公元元年元月元日零时零分正推年月日时分,问题是在转换输入值为分时是相当难的。如20年=?分,34月=?分
Originally posted by 26933062 at 2008-6-1 22:37:
Provide an idea
First, convert the month, day, time into days.
Then subtract the input year from the current year,
Then subtract the converted days from the result, and finally refine the time.
Thanks for your concern many times, brother. Please look at this set of values 20 34 600 4000 10000, going back 20 years, 34 months, 600 days, 4000 hours, 10000 minutes. I have an idea that is to calculate the time difference from the current system time to January 1, 00:00 of the first year of the AD as the number of minutes, then convert all the input time into the value counted in minutes, then subtract the input converted value from the system value, and then push forward the year, month, day, hour, minute from the reference value of January 1, 00:00 of the first year of the AD. The problem is that it is quite difficult to convert the input value into minutes. For example, how many minutes is 20 years =? and 34 months =?
|

批处理之家新域名:www.bathome.net |
|
2008-6-1 22:52 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
路过……
还是VBS爽嗬~~
Passing by...
Still VBS is refreshing~~
|

S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore |
|
2008-6-1 22:55 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
真的感觉好难啊,难道真用批处理就解决不了这个问题吗?
It really feels so difficult. Could it really be that batch processing can't solve this problem?
|

批处理之家新域名:www.bathome.net |
|
2008-6-1 23:00 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
会不会溢出
还有我运行上面的怎么老是错误
这个P的作用是什么
Will it overflow
Also, why do I always get an error when running the above
What is the role of this P
|

简单!简单!再简单! |
|
2008-6-1 23:05 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
若是全部转换为分的话将是一个超大数,那又牵扯到大数的计算问题。
另外还有个疑问:20年2个月600天4000个小时10000分钟
如上, 2 个月是指的什么? 比如今天是6月1日,2个月前是 4月1日吗?
还是当前时间减去 600天4000个小时10000分钟 以后的 2 个月?
If all are converted into minutes, it will be an extremely large number, and then it involves the problem of large number calculation.
In addition, there is another question: 20 years, 2 months, 600 days, 4000 hours, 10000 minutes
As above, what does 2 months refer to? For example, if today is June 1st, is 2 months ago April 1st?
Or 2 months after the current time minus 600 days, 4000 hours, 10000 minutes?
|

致精致简! |
|
2008-6-1 23:11 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2008-6-1 23:11:
若是全部转换为分的话将是一个超大数,那又牵扯到大数的计算问题。
另外还有个疑问:20年2个月600天4000个小时10000分钟
如上, 2 个月是指的什么 ...
20 34 600 4000 10000这个五个数值全是要经过推算的,不是简单的同位相减
Originally posted by 26933062 at 2008-6-1 23:11:
If all are converted to minutes, it will be an extremely large number, which then involves the problem of large number calculation.
In addition, there is another question: 20 years, 2 months, 600 days, 4000 hours, 10000 minutes
As above, what does 2 months refer to...
The five values 20, 34, 600, 4000, 10000 are all to be deduced through calculation, not simply subtraction of the same phase
|

批处理之家新域名:www.bathome.net |
|
2008-6-1 23:18 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
若是全部转换为分的话将是一个超大数,那又牵扯到大数的计算问题。
另外还有个疑问:20年2个月600天4000个小时10000分钟
如上, 2 个月是指的什么? 比如今天是6月1日,2个月前是 4月1日吗?
还是当前时间减去 600天4000个小时10000分钟 以后的 2 个月?
我觉得楼主的意思是:20年+2个月+600天+4000个小时+10000分钟
但感觉没什么意义,甚至.............唉
If all are converted into minutes, it will be an extremely large number, which then involves the problem of large number calculation.
In addition, there is another question: 20 years, 2 months, 600 days, 4000 hours, 10000 minutes
As above, what does 2 months refer to? For example, if today is June 1st, is 2 months ago April 1st?
Or is it 2 months after subtracting 600 days, 4000 hours, and 10000 minutes from the current time?
I think the building owner means: 20 years + 2 months + 600 days + 4000 hours + 10000 minutes
But it feels meaningless, and even............. alas
|
|
2008-6-1 23:19 |
|
|