显示网络时间的一小段VBS代码

Set t = CreateObject(“Microsoft.XMLHTTP”)
t.open “GET”, “http://su.baidu.com/cdn-cgi/trace/”, false
t.send()
s = Split(t.responseText,chr(10))(3)
s = right(s,len(s)-3)
s = DateAdd(“s”,s,”1970-01-01 00:00:00″)
s = DateAdd(“h”,8,s)
wsh.Echo s

改造成bat代码如下:

@echo off
if exist %tmp%\getTime.vbs (
del %tmp%\getTime.vbs
)
(
echo Set t = CreateObject(“Microsoft.XMLHTTP”^)
echo t.open “GET”, “http://su.baidu.com/cdn-cgi/trace/”, false
echo t.send(^)
echo s = Split(t.responseText,chr(10^)^)(3^)
echo s = right(s,len(s^)-3^)
echo s = DateAdd(“s”,s,”1970-01-01 00:00:00″^)
echo s = DateAdd(“h”,8,s^)
echo wsh.Echo s
)>%tmp%\getTime.vbs
for /f “tokens=1*” %%i in (‘cscript /nologo %tmp%\getTime.vbs’) do del %tmp%\getTime.vbs & date %%i & time %%j

发表评论

电子邮件地址不会被公开。 必填项已用*标注