欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

校准系统时间的VBS代码

程序员文章站 2022-04-10 13:44:33
复制代码 代码如下: 'vbs校准系统时间 by batman dim objxml, url, message message = "恭喜你,本机时间非常准确无需校对!"...
复制代码 代码如下:

'vbs校准系统时间 by batman
dim objxml, url, message
message = "恭喜你,本机时间非常准确无需校对!"
set objxml = createobject("msxml2.xmlhttp")
url = "http://open.baidu.com/special/time/"
objxml.open "get", url, false
objxml.send()
do until objxml.readystate = 4 : wscript.sleep 200 : loop
dim objstr, localdate
objstr = objxml.responsetext
localdate = now()
set objxml = nothing
dim objreg, regnum
set objreg = new regexp
objreg.global = true
objreg.ignorecase = true
objreg.pattern = "window.baidu_time\((\d{13,})\)"
regnum = int(objreg.execute(objstr)(0).submatches(0)) /1000
dim olddate, bjdate, num, num1
olddate = "1970-01-01 08:00:00"
bjdate = dateadd("s", regnum, olddate)
num = datediff("s", localdate, bjdate)
if abs(num) >=1 then
dim dm, dt, tm, objshell
dm = dateadd("s", num, now())
dt = datevalue(dm)
tm = timevalue(dm)
if instr(now, "午") then
dim arr, arr1, h24
arr = split(tm, " ")
arr1 = split(arr(1), ":")
h24 = arr1(0)
if arr(0) = "下午" then
h24 = h24 + 12
else
if h24 = 12 then h24 = 0
end if
tm = h24 & ":" & arr1(1) & ":" & arr1(2)
end if
set objshell = createobject("wscript.shell")
objshell.run "cmd /cdate " & dt, false, true
objshell.run "cmd /ctime " & tm, false, true
num1 = abs(datediff("s", now(), bjdate))
message = "【校准前】" & vbcrlf _
& "标准北京时间为:" & vbtab & bjdate & vbcrlf _
& "本机系统时间为:" & vbtab & localdate & vbcrlf _
& "与标准时间相差:" & vbtab & abs(num) & "秒" & vbcrlf & vbcrlf _
& "【校准后】" & vbcrlf _
& "本机系统时间为:" & vbtab & now() & vbcrlf _
& "与标准时间相差:" & vbtab & num1 & "秒"
set objshell = nothing
end if
wscript.echo message