Article From:https://www.cnblogs.com/ryueifu-VBA/p/9215309.html

The date and time of the computer system can be modified by users themselves. The following tools can automatically get the standard Beijing date and time, and modify the system time.

 

 

Code:

'By Liu Yongfu, QQ group: 61840693
Public IE As InternetExplorer
Sub GetDateTime()
    On Error GoTo Err1:
    Dim span_date As MSHTML.HTMLSpanElement
    Dim span_time As MSHTML.HTMLSpanElement
    Dim Sdate As String, Stime As String
    Set IE = New InternetExplorer
    With IE
        .Silent = True
        .Visible = False
        .navigate "https://www.baidu.com/s?wd=%E5%8C%97%E4%BA%AC%E6%97%B6%E9%97%B4"
        While .readyState <> READYSTATE_COMPLETE
            DoEvents
        Wend
        Do
            Set span_date = .document.getElementsByClassName("op-beijingtime-date").Item(0)
            DoEvents
            If span_date Is Nothing = False Then
                If IsDate(span_date.innerText) Then Exit Do
            End If
        Loop
        Sdate = Trim(span_date.innerText)
        Set span_time = .document.getElementsByClassName("op-beijingtime-time").Item(0)
        Stime = Trim(span_time.innerText)
        Date = CDate(Sdate)
        Time = CDate(Left(Stime, 5) & ":" & Right(Stime, 2))
        .Quit
    End With
    Exit Sub
Err1:
    MsgBox Err.Description
End Sub

 

Download the Annex:

Download address

Leave a Reply

Your email address will not be published. Required fields are marked *