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-07-31 05:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] How to make a variable's value equal to the current system time plus two minutes View 2,673 Replies 15
Original Poster Posted 2008-05-10 18:44 ·  中国 上海 电信
初级用户
★★
Credits 160
Posts 81
Joined 2006-07-27 17:52
20-year member
UID 59377
Gender Male
Status Offline
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 ]
Floor 2 Posted 2008-05-10 18:57 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
```
@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 ]
致精致简!
Floor 3 Posted 2008-05-10 19:31 ·  中国 江西 南昌 电信
初级用户
Credits 82
Posts 34
Joined 2008-04-29 19:37
18-year member
UID 117307
Gender Male
From 江西
Status Offline
@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 ]
Floor 4 Posted 2008-05-10 19:48 ·  中国 上海 电信
初级用户
★★
Credits 160
Posts 81
Joined 2006-07-27 17:52
20-year member
UID 59377
Gender Male
Status Offline
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?
Floor 5 Posted 2008-05-10 19:51 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
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.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
wfy150 +1 2008-05-11 01:54
致精致简!
Floor 6 Posted 2008-05-10 19:52 ·  中国 上海 电信
初级用户
★★
Credits 160
Posts 81
Joined 2006-07-27 17:52
20-year member
UID 59377
Gender Male
Status Offline
Thanks for the reply from wfy150. If the current time is 19:58, it's incorrect.
Floor 7 Posted 2008-05-10 20:33 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
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.
致精致简!
Floor 8 Posted 2008-05-10 20:39 ·  中国 湖北 武汉 电信
初级用户
Credits 24
Posts 6
Joined 2008-05-10 19:55
18-year member
UID 118357
Gender Male
Status Offline
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!
Floor 9 Posted 2008-05-11 01:53 ·  中国 江西 南昌 电信
初级用户
Credits 82
Posts 34
Joined 2008-04-29 19:37
18-year member
UID 117307
Gender Male
From 江西
Status Offline
Didn't notice this problem, learned something.
Floor 10 Posted 2008-05-11 02:00 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
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!
Floor 11 Posted 2008-05-11 02:27 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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.
Floor 12 Posted 2008-05-11 04:18 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
I think to write general - purpose code for such problems, it's still more convenient to call VBS.
Floor 13 Posted 2008-05-11 12:28 ·  中国 上海 松江区 电信
初级用户
★★
Credits 160
Posts 81
Joined 2006-07-27 17:52
20-year member
UID 59377
Gender Male
Status Offline
Thanks to everyone's enthusiastic help,

Learned a lot
Floor 14 Posted 2008-12-12 14:34 ·  中国 江西 宜春 电信
初级用户
Credits 152
Posts 42
Joined 2004-03-10 00:00
22-year member
UID 19790
Gender Male
Status Offline
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?
Floor 15 Posted 2009-01-05 10:18 ·  中国 江西 宜春 电信
初级用户
Credits 152
Posts 42
Joined 2004-03-10 00:00
22-year member
UID 19790
Gender Male
Status Offline
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


::@echo off
set /a step=1

for /f "tokens=1,2 delims=:." %%a in ("%time%") do (
set /a t=100%%a%%100, h=100%%b%%100+%step%
)
set /a s=(t+h/60)%%24,f=h%%60
set s=0%s%&set "f=0%f%"

:set /a rq=%date:~0,4%%date:~5,2%%date:~8,2% >nul 2>nul
set /a nian=%date:~0,4%,yue=%date:~5,2%,ri=%date:~8,2%

echo %nian%年%yue%月%ri%日 %s:~-2%:%f:~-2% >>C:\test\test.txt
::start notepad.exe C:\test\test.txt

at /d /y
at %s:~-2%:%f:~-2% /interactive C:\test\new.vbs
::pause
::exit


new.vbs


set Cleaner=createobject("wscript.shell")
Cleaner.run "cmd /c C:\test\new.bat",vbhide


[ Last edited by kyqm on 2009-1-14 at 14:46 ]
Forum Jump: