設(shè)計界面雙擊那個按鈕(自動跳到代碼里)
創(chuàng)新互聯(lián)建站主要為客戶提供服務(wù)項目涵蓋了網(wǎng)頁視覺設(shè)計、VI標(biāo)志設(shè)計、營銷推廣、網(wǎng)站程序開發(fā)、HTML5響應(yīng)式重慶網(wǎng)站建設(shè)公司、手機網(wǎng)站制作設(shè)計、微商城、網(wǎng)站托管及網(wǎng)站維護、WEB系統(tǒng)開發(fā)、域名注冊、國內(nèi)外服務(wù)器租用、視頻、平面設(shè)計、SEO優(yōu)化排名。設(shè)計、前端、后端三個建站步驟的完善服務(wù)體系。一人跟蹤測試的建站服務(wù)標(biāo)準(zhǔn)。已經(jīng)為PE包裝袋行業(yè)客戶提供了網(wǎng)站營銷服務(wù)。
然后輸入 要顯示時間的那個Label.Text = DateTime.Now.ToString()
你是指Internet上的國際標(biāo)準(zhǔn)時間嗎。
先加入控件 AxWinsock1 在.Com中Microsoft.Winsock
Public Class Form1
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)
Dim NoSrv As Boolean
Dim TimeFromNet As String
Dim OldTime As Date
Dim NewTime As Date
Dim MyDate As Date
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If AxWinsock1.CtlState MSWinsockLib.StateConstants.sckClosed Then AxWinsock1.Close()
AxWinsock1.Protocol = MSWinsockLib.ProtocolConstants.sckTCPProtocol
NetTime("") '首先取中科院國家授時中心時間
If NoSrv Or TimeFromNet = "" Then
NetTime("time.nist.gov") '取美國標(biāo)準(zhǔn)技時院時間
If NoSrv Or TimeFromNet = "" Then
MsgBox("檢測不到網(wǎng)絡(luò)標(biāo)準(zhǔn)時間服務(wù)器time.nist.gov!")
Else
NetTime("time.nist.gov")
If TimeFromNet = "" Then
MsgBox("網(wǎng)絡(luò)標(biāo)準(zhǔn)時間服務(wù)器time.nist.gov超時!")
Else
MyDate = Mid(TimeFromNet, 8, 8)
OldTime = Mid(TimeFromNet, 17, 8)
NewTime = TimeSerial((Hour(OldTime) + 8) Mod 24, Minute(OldTime), Second(OldTime))
Dim MyTime As DateTime = MyDate Space(1) NewTime
MsgBox(MyTime)
'SetWindowsClock(MyTime)
End If
End If
Else
'使網(wǎng)絡(luò)誤差時間小,第2次再中科院國家授時中心時間
NetTime("")
If TimeFromNet = "" Then
MsgBox("網(wǎng)絡(luò)標(biāo)準(zhǔn)時間服務(wù)器超時!")
Else
MyDate = Mid(TimeFromNet, 8, 8)
NewTime = Mid(TimeFromNet, 17, 8)
Dim MyTime As DateTime = MyDate Space(1) NewTime
MsgBox(MyTime)
'SetWindowsClock(MyTime)
End If
End If
End Sub
Private Sub NetTime(ByVal TimeSrv As String)
NoSrv = False
TimeFromNet = ""
If AxWinsock1.CtlState MSWinsockLib.StateConstants.sckClosed Then AxWinsock1.Close()
AxWinsock1.RemoteHost = TimeSrv ' "" 或 "time.nist.gov"
AxWinsock1.RemotePort = 13
AxWinsock1.LocalPort = 0
AxWinsock1.Connect()
Do While TimeFromNet = ""
If NoSrv Then Exit Do
Sleep(55)
System.Windows.Forms.Application.DoEvents()
Loop
If AxWinsock1.CtlState MSWinsockLib.StateConstants.sckClosed Then AxWinsock1.Close()
End Sub
Private Sub AxAxWinsock1_CloseEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxWinsock1.CloseEvent
AxWinsock1.Close()
End Sub
Private Sub AxAxWinsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
AxWinsock1.GetData(TimeFromNet)
End Sub
Private Sub AxAxWinsock1_Error(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent) Handles AxWinsock1.Error
NoSrv = True
End Sub
End Class
將datePicker設(shè)置為該日期,這樣就可以確保每次從nib中加載此視圖時,選取器都會重置為當(dāng)前得日期和時間就可以了。
'添加一個label標(biāo)簽名字label1 用來顯示時間
'再添加一個timer控件 名字timer1 interval屬性=1000 用來計時
'窗體添加代碼
Dim t As Date '用來記錄時間
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
t = t.AddSeconds(1)
Label1.Text = "登錄時間:" t.TimeOfDay.ToString
End Sub
Label1.Text?=?"12時演示:"?+?Now.ToString("yyyy-MM-dd?hh:mm:ss")
Label2.Text?=?"24時演示:"?+?Now.ToString("yyyy-MM-dd?HH:mm:ss")
Label3.Text?=?"UTC時演示:"?+?System.DateTime.UtcNow.ToString("yyyy-MM-dd?HH:mm:ss")
Label4.Text?=?"時間為不補0:"?+?Now.ToString("yyyy-MM-dd?H:m:s")
Label5.Text?=?"時間戳:"?+?CLng(System.DateTime.UtcNow.Subtract(New?Date(1970,?1,?1,?0,?0,?0)).TotalMilliseconds).ToString
定時器中處理
Private?Sub?Form1_Load(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?MyBase.Load
Timer1.Interval?=?10?'10毫秒刷新一次
Timer1.Start()?'開啟定時器
End?Sub
Private?Sub?Timer1_Tick(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Timer1.Tick
Label1.Text?=?Now
End?Sub
網(wǎng)站名稱:vb.net實時時間的簡單介紹
分享地址:http://www.rwnh.cn/article32/doohspc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、動態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、App開發(fā)、網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)