1个回答
展开全部
Imports vb = Microsoft.VisualBasic
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj, OBJStatus, url, GetText, i
Dim Retrieval
url = "http://www.163.com"
'判断网络是否连接
If url <> "" Then
Retrieval = GetObject("winmgmts:\\.\root\cimv2")
obj = Retrieval.ExecQuery("Select * From Win32_PingStatus Where Address = '" & Mid(url, 8) & "'")
For Each OBJStatus In obj
If vb.Information.IsDBNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
Exit Sub
Else
Exit For '已连接则继续
End If
Next
End If
'通过下载网页头信息获取网络时间
Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open("Get", url, False, "", "")
.setRequestHeader("If-Modified-Since", "0")
.setRequestHeader("Cache-Control", "no-cache")
.setRequestHeader("Connection", "close")
.Send()
If .Readystate <> 4 Then Exit Sub
GetText = .getAllResponseHeaders()
i = InStr(1, GetText, "date:", vbTextCompare)
If i > 0 Then '网页下载成功
i = InStr(i, GetText, ",", vbTextCompare)
GetText = Trim(Mid(GetText, i + 1))
i = InStr(1, GetText, " GMT", vbTextCompare)
GetText = vb.Left(GetText, i - 1)
MsgBox("网络时间:" & GetText)
End If
End With
Retrieval = Nothing
OBJStatus = Nothing
obj = Nothing
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj, OBJStatus, url, GetText, i
Dim Retrieval
url = "http://www.163.com"
'判断网络是否连接
If url <> "" Then
Retrieval = GetObject("winmgmts:\\.\root\cimv2")
obj = Retrieval.ExecQuery("Select * From Win32_PingStatus Where Address = '" & Mid(url, 8) & "'")
For Each OBJStatus In obj
If vb.Information.IsDBNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
Exit Sub
Else
Exit For '已连接则继续
End If
Next
End If
'通过下载网页头信息获取网络时间
Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open("Get", url, False, "", "")
.setRequestHeader("If-Modified-Since", "0")
.setRequestHeader("Cache-Control", "no-cache")
.setRequestHeader("Connection", "close")
.Send()
If .Readystate <> 4 Then Exit Sub
GetText = .getAllResponseHeaders()
i = InStr(1, GetText, "date:", vbTextCompare)
If i > 0 Then '网页下载成功
i = InStr(i, GetText, ",", vbTextCompare)
GetText = Trim(Mid(GetText, i + 1))
i = InStr(1, GetText, " GMT", vbTextCompare)
GetText = vb.Left(GetText, i - 1)
MsgBox("网络时间:" & GetText)
End If
End With
Retrieval = Nothing
OBJStatus = Nothing
obj = Nothing
End Sub
End Class
追问
时间差很多...差了9个小时.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
快又稳
2024-10-28 广告
2024-10-28 广告
Apache基于域名的虚拟主机配置主要涉及到在Apache配置文件中为不同域名指定不同的网站目录和日志路径。配置时,需确保域名已正确指向服务器的IP地址。在Apache的`httpd-vhosts.conf`或类似配置文件中,为每个域名创建...
点击进入详情页
本回答由快又稳提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询