
求助,求从网络读取时间的vb代码
展开全部
'Download by http://www.newxing.com/
Private Function GetHtml(Url As String)
Dim xmlHttp As Object
Set xmlHttp = CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "GET", Url, True
xmlHttp.send (Null)
While xmlHttp.ReadyState <> 4
DoEvents
Wend
GetHtml = xmlHttp.responseText
End Function
Private Function getTime() As Date
Dim Regex As Object, ms As Object, m As Object
Dim HTML As String
HTML = GetHtml("http://www.time.ac.cn/timeflash.asp?user=flash")
Set Regex = CreateObject("VBSCRIPT.REGEXP")
Regex.IgnoreCase = True
Regex.Pattern = "<year>(\d+)</year><month>(\d+)</month><day>(\d+)</day>.+?<hour>(\d+)</hour><minite>(\d+)</minite><second>(\d+)</second>"
Set ms = Regex.Execute(HTML)
If ms.Count = 0 Then
getTime = Now()
Else
Dim t As String
t = ms.Item(0).SubMatches(0) _
& "-" & ms.Item(0).SubMatches(1) _
& "-" & ms.Item(0).SubMatches(2) _
& " " & ms.Item(0).SubMatches(3) _
& ":" & ms.Item(0).SubMatches(4) _
& ":" & ms.Item(0).SubMatches(5)
If IsDate(t) Then getTime = CDate(t) Else getTime = Now()
End If
End Function
Private Sub Form_Load()
MsgBox getTime
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询