Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use vbs to calibrate system time

Shulou Source: shulou.com Published: 2022-06-03 07:15:03 10月03日 Update

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!

Tags: Time system standard local machine content more standard time article good practical code article proofread see knowledge Beijing reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Apple Shulou Tech Info Microsoft