回复 5楼 lowxiong
Private Sub Command1_Click()
Timer1.Enabled = True
Command1.Enabled = False
Command1.Caption = "已获取时间"
End Sub
Public Function GETHTML(url As String)
'使用 a814153 的代码 进行封装
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", url, False
.Send
GETHTML = .responsetext
End With
End Function
Private Sub Command2_Click()
Time = Right(Label1.Caption, 8)
End Sub
Function GetTime()
Dim url As String
Dim s As String
url = "http://www.
s = GETHTML(url)
Dim i As Long, j As Long
i = InStr(1, s, "lb_DBTIME") '先找ID
i = InStr(i, s, ">") '再找这个标记的关闭字符
j = InStr(i, s, "<") '找下一个标记开始的字符
If j > i Then
Label1.Caption = "服务器的时间:" & Mid(s, i + 1, j - i - 1)
'MsgBox "服务器时间:" & Mid(s, i + 1, j - i - 1)
Else
'MsgBox "获取时间失败"
End If
End Function
Private Sub Timer1_Timer()
GetTime
End Sub
Private Sub Timer2_Timer()
Label2.Caption = "本机电脑时间:" & Format(Now, "yyyy-mm-dd hh:mm:ss")
End Sub
我这个做出来,校对时间怎么样都有1S的误差。我哪儿弄错了吗?