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-08-07 12:13
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] Get the current system time with VBS and add an at task View 2,871 Replies 27
Floor 16 Posted 2008-01-26 21:41 ·  中国 湖南 常德 电信
中级用户
★★
Credits 231
Posts 102
Joined 2008-01-25 23:45
18-year member
UID 109557
Gender Male
Status Offline
It has been considered.

So.


a=Wsh.Run("at " & hour(now) & ":" & ((minute(now)+5) mod 60) & " 1.vbs",0,False)

Problem solved
Floor 17 Posted 2008-01-26 21:44 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Forget it, just give you the code. AT doesn't support AM/PM, and it also needs to format it in 24-hour format.
NewTime = Split(Time, ":" ,-1)
if NewTime(1)+5 > 59 Then
mm=NewTime(1)+5-60
Newnn=Split(NewTime(0), " " ,-1)
if Newnn(1)+1 = 13 Then
nn="01"
else
nn=Newnn(1)+1
end if
Times = Newnn(0) & " " & nn & chr(58) & mm & chr(58) & NewTime(2)
else
Times = NewTime(0) & chr(58) & NewTime(1)+5 & chr(58) & NewTime(2)
end if

dim wsh
set wsh=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
command = "at " &Chr(34) & FormatDateTime (Times ,vbShortTime) &Chr(34) &" 1.vbs"
retodate=wsh.Run(command),vbHide
第一高手 第二高手

Floor 18 Posted 2008-01-26 21:54 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
hour(now)&":"&((minute(now)+5) mod 60
第一高手 第二高手

Floor 19 Posted 2008-01-26 22:35 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
f
Newnn = Split(NewTime(0), " ", -1)
Is this working for you?

h?
Did you consider that? You'll have to wait a whole day for it to run like that?

12:56 + 5 = 13:01

Running it at 12:01 like that... that's called considering...
Floor 20 Posted 2008-01-26 22:59 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Newnn = Split(NewTime(0), " ", -1)
if Newnn(1) + 1 = 13 Then
nn = "01"
else
nn = Newnn(1) + 1
end if
Has been converted
第一高手 第二高手

Floor 21 Posted 2008-01-26 23:02 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
The "NewTime(0)" does not contain spaces... What do you mean by that? After splitting by spaces, newnn(1) does not exist... Then you will have a subscript out of bounds...

The first time you split time, 0, 1, 2 are h, m, s respectively
Floor 22 Posted 2008-01-26 23:14 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Wscript.echo Time
Afternoon space HH:MM:SS

TimeTmp="Afternoon 12:56:00"
NewTime = Split(TimeTmp, ":" ,-1)
if NewTime(1)+5 > 59 Then
mm=NewTime(1)+5-60
Newnn=Split(NewTime(0), " " ,-1)
if Newnn(1)+1 = 13 Then
nn="01"
else
nn=Newnn(1)+1
end if
Times = Newnn(0) & " " & nn & chr(58) & mm & chr(58) & NewTime(2)
else
Times = NewTime(0) & chr(58) & NewTime(1)+5 & chr(58) & NewTime(2)
end if
Wscript.echo Times
Wscript.echo FormatDateTime (Times ,vbShortTime)
第一高手 第二高手

Floor 23 Posted 2008-01-26 23:19 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Discussing which of the two codes can achieve the LZ's purpose is meaningless.
第一高手 第二高手

Floor 24 Posted 2008-01-26 23:22 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Originally posted by fastslz at 2008-1-26 23:19:
The discussion about the two types of code achieving the LZ's purpose is meaningless



......It means that when the system selects the 24-hour system, the word "afternoon" will not appear...
The portability of this code...

His code does not do carry although it is one sentence...

I mean this problem... has nothing to do with the method.
Floor 25 Posted 2008-01-26 23:27 ·  中国 湖南 常德 汉寿县 电信
中级用户
★★
Credits 231
Posts 102
Joined 2008-01-25 23:45
18-year member
UID 109557
Gender Male
Status Offline
Oh yeah. The discussion is really intense. Of course my sentence is just to achieve my purpose, because I don't need the judgment of morning and afternoon, just let the system add 5 to the time.

What everyone discussed is also right. It's another train of thought

No matter what method, I just hope the code can be as concise as possible

[ Last edited by hackhd on 2008-1-26 at 11:29 PM ]
Floor 26 Posted 2008-01-27 01:14 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Just one DateAdd
Wscript.echo FormatDateTime(DateAdd("n",5,now),vbShortTime)
Floor 27 Posted 2008-01-27 14:35 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Oh, the DateAdd function is actually so simple. I overcomplicated it before. Vbs time conversion is too flexible. If one has a good command of English in writing vbs scripts, it's like writing short sentences. The reason why the Chinese software industry is not as good as the later - catching - up India is also because of the language barrier of localization.
第一高手 第二高手

Floor 28 Posted 2008-01-27 19:07 ·  中国 湖南 常德 电信
中级用户
★★
Credits 231
Posts 102
Joined 2008-01-25 23:45
18-year member
UID 109557
Gender Male
Status Offline
Wsh.Run "at " & hour(now) & ":" & ((minute(now) + 5) mod 60) & " 1.vbs", 0, False
FormatDateTime(DateAdd("n", 5, now), vbShortTime)
It's also good.
Forum Jump: