求助,求从网络读取时间的vb代码

 我来答
sbj518
2017-05-18 · TA获得超过4.4万个赞
知道大有可为答主
回答量:1.1万
采纳率:81%
帮助的人:5563万
展开全部
'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
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式