Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use vbs to calibrate system time

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to use vbs to calibrate system time. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The code is as follows:

'VBS Calibration system time BY BatMan

Dim objXML, Url, Message

Message = "Congratulations, the local time is very accurate and there is no need to proofread!"

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, noon) Then

Dim Arr, Arr1, h34

Arr = Split (TM, "")

Arr1 = Split (Arr (1), ":")

H34 = Arr1 (0)

If Arr (0) = "afternoon" Then

H34 = H34 + 12

Else

If H34 = 12 Then H34 = 0

End If

TM = H34 & ":" & 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 = "[before calibration]" & vbCrLf _

& "Standard Beijing time is:" & vbTab & BJDate & vbCrLf _

& "Local system time is:" & vbTab & LocalDate & vbCrLf _

& "difference from standard time:" & vbTab & Abs (Num) & "seconds" & vbCrLf & vbCrLf _

& "[after calibration]" & vbCrLf _

& "Local system time is:" & vbTab & Now () & vbCrLf _

& "difference from standard time" & vbTab & Num1 & "seconds"

Set objSHELL = Nothing

End If

WScript.Echo Message

Thank you for reading! This is the end of this article on "how to use vbs Calibration system time". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report