中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-22 02:02
47,812 topics / 349,917 posts / today 0 new / 48,271 members
DOS批处理 & 脚本技术(批处理室) » [Closed] How to make a variable's value equal to the current system time plus two minutes
Printable Version  3,040 / 15
Floor1 jia332 Posted 2008-05-10 18:44
初级用户 Posts 81 Credits 160
As the title. For example, the current time is 18:30, and I want the value of the variable to be 18:32. Thanks

[ Last edited by HAT on 2009-1-5 at 13:56 ]
Floor2 26933062 Posted 2008-05-10 18:57
银牌会员 Posts 879 Credits 2,268
```
@echo off
echo Current system time: %time:~0,5%
for /f "tokens=1,2 delims=:." %%a in ("%time%") do (
set /a t=100%%a%%100,h=100%%b%%100+2
)
set /a s=(t+h/60)%%24,f=h%%60
set s=0%s%&set "f=0%f%"
echo Time after adding two minutes: %s:~-2%:%f:~-2%
echo.&pause
```

[ Last edited by 26933062 on 2008-5-10 at 07:08 PM ]
Floor3 wfy150 Posted 2008-05-10 19:31
初级用户 Posts 34 Credits 82 From 江西
@echo off
for /f "tokens=1,2 delims=:." %%a in ("%time%") do (
set t1=%%a
set t2=%%b
set /a t3=t2+2
)
echo The current time is: %t1%:%t2%
echo The time two minutes later is: %t1%:%t3%
pause>nul

[ Last edited by wfy150 on 2008-5-10 at 07:33 PM ]
Floor4 jia332 Posted 2008-05-10 19:48
初级用户 Posts 81 Credits 160
Please clarify the specific context or code structure around these `set /a` commands. The current information is a bit insufficient to accurately translate and explain the difference clearly. Can you provide more details about the overall code where these lines are located?
Floor5 26933062 Posted 2008-05-10 19:51
银牌会员 Posts 879 Credits 2,268
What you described in the 3rd floor is simple, but there are several situations not taken into account.
1. When the hour or minute is 08 or 09, it will go wrong.
2. When the time is 23:58, it will go wrong.
3. When the minute is 58 or 59, your hour will not carry over.
Floor6 jia332 Posted 2008-05-10 19:52
初级用户 Posts 81 Credits 160
Thanks for the reply from wfy150. If the current time is 19:58, it's incorrect.
Floor7 26933062 Posted 2008-05-10 20:33
银牌会员 Posts 879 Credits 2,268
Reply to floor 4
Suppose %%a=08 %%b=9
set /a t=100%%a%%100,h=100%%b%%100
The result is to ignore the leading 0, so that a correct number is obtained, and the calculation will not go wrong.
To understand the remainder of set /a specifically, you will know.
Floor8 40961434 Posted 2008-05-10 20:39
初级用户 Posts 6 Credits 24
Ladies and gentlemen, I'm sorry to interrupt your train of thought!
But I'm really in a hurry! Please help me! Let me say thank you first!
The HTML and HTM files on my computer are all written with:
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
The ASP files are written with: <iframe width=0 height=0></iframe> statement
I'm begging all the gentlemen to help!
Floor9 wfy150 Posted 2008-05-11 01:53
初级用户 Posts 34 Credits 82 From 江西
Didn't notice this problem, learned something.
Floor10 pusofalse Posted 2008-05-11 02:00
银牌会员 Posts 646 Credits 1,604
I used to write something similar... Experts, please help take a look

set /a min=%time:~3,2%+1,clo=%time:~0,2%
if %min% equ 60 set min=00&set/a clo=%time:~0,2%+1
if %clo% equ 24 set clo=00
at %clo%:%min% %0

It's under the assumption that the minute value is not 08, 09. The first two lines run normally. But if after adding 1 to the current hour value it becomes 24, the line that resets it to 00 doesn't execute... Where is the mistake? Experts, please guide!
Floor11 slore Posted 2008-05-11 02:27
铂金会员 Posts 2,478 Credits 5,212
set/a clo=23+1
if %clo% equ 24 set clo=00

Executed?
Too lazy to change the time...

You didn't have echo off here
Copy the screen information with the time problem and show it to me.
Floor12 HAT Posted 2008-05-11 04:18
版主 Posts 5,017 Credits 9,023
I think to write general - purpose code for such problems, it's still more convenient to call VBS.
Floor13 jia332 Posted 2008-05-11 12:28
初级用户 Posts 81 Credits 160
Thanks to everyone's enthusiastic help,

Learned a lot
Floor14 kyqm Posted 2008-12-12 14:34
初级用户 Posts 42 Credits 152
Strange, the code on the 2nd floor.
A machine worked normally yesterday but not today.
Another machine is fine.
Did I accidentally modify something in the system?
Floor15 kyqm Posted 2009-01-05 10:18
初级用户 Posts 42 Credits 152
After testing, it is found that the code on the 2nd floor will have an error when the time is 0X:XX.

The following is my test new.bat



new.vbs



[ Last edited by kyqm on 2009-1-14 at 14:46 ]
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023