Dim?obj,OBJStatus?As?Object,url?As?String,GetText?As?String,i?As?Integer
成都創(chuàng)新互聯(lián)從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站制作、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元和平做網(wǎng)站,已為上家服務(wù),為和平各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
Dim?Retrieval
url=""
'判斷網(wǎng)絡(luò)是否連接
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'已連接則繼續(xù)
End?If
Next
End?If
'通過(guò)下載網(wǎng)頁(yè)頭信息獲取網(wǎng)絡(luò)時(shí)間
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'網(wǎng)頁(yè)下載成功
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?("網(wǎng)絡(luò)時(shí)間:"GetText)
End?If
End?With
Retrieval=Nothing
OBJStatus=Nothing
obj=Nothing
兩種方式自己選用
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
Sub?gettime()
nowtime?=?Format(DateTime.Now,?"yyyy/MM/dd?hh:mm:ss")
MsgBox?nowtime
End?Sub
其中DateTime.Now為當(dāng)前系統(tǒng)的時(shí)間
Format是設(shè)置時(shí)間格式
效果如下
用大寫(xiě)的H可以顯示24小時(shí)制:
(Format(DateTime.Now, "yyyyMMddHHmmss")).ToString