VBS code for system time Calibration

Source: Internet
Author: User
Tags echo message

Copy codeThe Code is as follows: 'vbs calibration system time BY BatMan
Dim objXML, Url, Message
Message = "congratulations, the local time is very accurate and you do not need to proofread it! "
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 = "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, "Wu") Then
Dim Arr, Arr1, h24
Arr = Split (TM ,"")
Arr1 = Split (Arr (1 ),":")
H24 = Arr1 (0)
If Arr (0) = "Afternoon" 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 = "[before calibration]" & vbCrLf _
& "Standard Beijing time:" & vbTab & BJDate & vbCrLf _
& "Local system time:" & vbTab & LocalDate & vbCrLf _
& "Difference from standard time:" & vbTab & Abs (Num) & "second" & vbCrLf _
& "[After calibration]" & vbCrLf _
& "Local system time:" & vbTab & Now () & vbCrLf _
& "Difference from standard time:" & vbTab & Num1 & "seconds"
Set objSHELL = Nothing
End If
WScript. Echo Message
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.