vb.net 获取互联网的北京时间
vb.net如何获取互联网的北京时间(求代码),注意是:vb.net是visualstudio2010开发的...
vb.net如何获取互联网的北京时间(求代码),注意是:vb.net
是visual studio 2010开发的 展开
是visual studio 2010开发的 展开
2个回答
展开全部
Public Function GetBeijingTime() As DateTime
Dim dt As DateTime
Dim wrt As WebRequest = Nothing
Dim wrp As WebResponse = Nothing
Try
wrt = WebRequest.Create("http://www.beijing-time.org/time.asp")
wrp = wrt.GetResponse()
Dim html As String = String.Empty
Using stream As Stream = wrp.GetResponseStream()
Using sr As New StreamReader(stream, Encoding.UTF8)
html = sr.ReadToEnd()
End Using
End Using
Dim tempArray As String() = html.Split(";"c)
For i As Integer = 0 To tempArray.Length - 1
tempArray(i) = tempArray(i).Replace(vbCr & vbLf, "")
Next
Dim year As String = tempArray(1).Split("="c)(1)
Dim month As String = tempArray(2).Split("="c)(1)
Dim day As String = tempArray(3).Split("="c)(1)
Dim hour As String = tempArray(5).Split("="c)(1)
Dim minite As String = tempArray(6).Split("="c)(1)
Dim second As String = tempArray(7).Split("="c)(1)
dt = DateTime.Parse(year & "-" & month & "-" & day & " " & hour & ":" & minite & ":" & second)
Catch generatedExceptionName As WebException
Return DateTime.Parse("2011-1-1")
Catch generatedExceptionName As Exception
Return DateTime.Parse("2011-1-1")
Finally
If wrp IsNot Nothing Then
wrp.Close()
End If
If wrt IsNot Nothing Then
wrt.Abort()
End If
End Try
Return dt
End Function
展开全部
Public Function getWebDatetime()
Dim XmlHttp As Object
XmlHttp = CreateObject("Microsoft.XMLHTTP")
XmlHttp.Open("POST", "https://www.baidu.com/", False)
XmlHttp.send()
getWebDatetime = (CDate(Date.FromOADate(1 / 3 + CDbl(CDate(Mid$(XmlHttp.getResponseHeader("Date"), 5, 21)).ToOADate()))))
XmlHttp = Nothing
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询