vb.net获取时间的简单介绍
vb。net怎么获取网络上的时间 坐等
Dim obj,OBJStatus As Object,url As String,GetText As String,i As Integer
成都创新互联从2013年创立,是专业互联网技术服务公司,拥有项目网站制作、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元和平做网站,已为上家服务,为和平各地企业和个人服务,联系电话:13518219792
Dim Retrieval
url=""
'判断网络是否连接
If url""Then
Retrieval=GetObject("winmgmts:\\.\root\cimv2")
obj=Retrieval.ExecQuery("Select*FromWin32_PingStatusWhereAddress='"Mid(url,8)"'")
For Each OBJStatus In obj
If IsNothing(OBJStatus.StatusCode) Or OBJStatus.StatusCode0 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.Readystate4 Then Exit Sub
GetText=.getAllResponseHeaders()
i=InStr(1,GetText,"date:",vbTextCompare)
If i0 Then'网页下载成功
i=InStr(i,GetText,",",vbTextCompare)
GetText= Trim(Mid(GetText,i+1))
i=InStr(1,GetText,"GMT",vbTextCompare)
GetText=GetText.Substring(0,i-1)' Left(GetText,i-1)
MsgBox ("网络时间:"GetText)
End If
End With
Retrieval=Nothing
OBJStatus=Nothing
obj=Nothing
vb.net 如何获取时间?
两种方式自己选用
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = DateTime.Today.Year()
s = s DateTime.Today.Month()
s = s DateTime.Today.Day()
s = s DateTime.Now.Hour()
s = s DateTime.Now.Minute()
s = s DateTime.Now.Second()
MsgBox(s, vbDefaultButton1, Now())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim s As String
s = Format(Now(), "yyyymmddhhmmss")
MsgBox(s, vbYes, Now())
End Sub
vb net获取系统时间
Sub gettime()
nowtime = Format(DateTime.Now, "yyyy/MM/dd hh:mm:ss")
MsgBox nowtime
End Sub
其中DateTime.Now为当前系统的时间
Format是设置时间格式
效果如下
vb.net如何获取完整时间
用大写的H可以显示24小时制:
(Format(DateTime.Now, "yyyyMMddHHmmss")).ToString
网站栏目:vb.net获取时间的简单介绍
URL地址:http://hbruida.cn/article/hjhdec.html