'使用本代码需要Ctrl+T里面勾选Microsoft Internet Control 6.0,并在窗体上画一个,默认名称是WebBrowser1
'然后添加一个文本框Label1和一个按钮Timer1
Private Sub Form_Load()
Label1.Caption = ""
Label1.AutoSize = True '自动调整大小
WebBrowser1.Width = 0 '为了不让其显示出来,设置宽度为0
WebBrowser1.Height = 0 ''为了不让其显示出来,设置高度为0
WebBrowser1.Navigate "https://gss0.baidu.com/8aQDcnSm2Q5IlBGlnYG/static/time/beijingtime.html"
End Sub
Private Sub Timer1_Timer()
ss = WebBrowser1.Document.body.innerText '得到所有文字
aa = "您的本地电脑时间" '找出要分离的文字前面有标志性的文字
bb = InStr(1, ss, aa) '确定位置
cc = Mid(ss, bb + Len(aa) + 1, 14) '取出要的东西
Label1.Caption = "国家授时中心标准时间:" & Trim(cc) '显示出来
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Timer1.Interval = 100 '每秒更新一次
Timer1.Enabled = True '启动定时器
End Sub