用VB.net做一个时间计时器'添加一个label标签名字label1 用来显示时间
'再添加一个timer控件 名字timer1interval属性=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
Vb.net 2008 如何获取网络时间vb.net独立时间你是指Internet上vb.net独立时间的国际标准时间吗 。
先加入控件 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.CtlStateMSWinsockLib.StateConstants.sckClosed Then AxWinsock1.Close()
AxWinsock1.Protocol = MSWinsockLib.ProtocolConstants.sckTCPProtocol
NetTime("") '首先取中科院国家授时中心时间
If NoSrv Or TimeFromNet = "" Then
NetTime("time.nist.gov") '取美国标准技时院时间
If NoSrv Or TimeFromNet = "" Then
MsgBox("检测不到网络标准时间服务器time.nist.govvb.net独立时间!")
Else
NetTime("time.nist.gov")
If TimeFromNet = "" Then
MsgBox("网络标准时间服务器time.nist.gov超时vb.net独立时间!")
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 = MyDateSpace(1)NewTime
MsgBox(MyTime)
'SetWindowsClock(MyTime)
End If
End If
Else
'使网络误差时间小vb.net独立时间,第2次再中科院国家授时中心时间
NetTime("")
If TimeFromNet = "" Then
MsgBox("网络标准时间服务器超时!")
Else
MyDate = Mid(TimeFromNet, 8, 8)
NewTime = Mid(TimeFromNet, 17, 8)
Dim MyTime As DateTime = MyDateSpace(1)NewTime
MsgBox(MyTime)
'SetWindowsClock(MyTime)
End If
End If
End Sub
【vb.net独立时间的简单介绍】Private Sub NetTime(ByVal TimeSrv As String)
NoSrv = False
TimeFromNet = ""
If AxWinsock1.CtlStateMSWinsockLib.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.CtlStateMSWinsockLib.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
vb.net里的时间函数问题dim date as DateTime = DateTime.Parse(TextBox1.Text)
TextBox2.Text = date.ToShortDateTime()
日期类型有好多种转换表达式,特别的使用.ToString("YYYY-mm-dd") 这种形式可以自定义ToString里面的格式化样式 。
怎么在VB.net中实时显示时间定时器中处理
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
推荐阅读
- 合欢视频ios软件,合欢视频ios软件
- 视觉营销如何定位营销者,视觉营销的四个关键点
- 无敌的单机游戏,好玩的无敌版单机游戏
- 无人机直播西班牙人,无人机直播西班牙人是真的吗
- MySQL主机名怎么填 mysql创建登录名
- win10怎么安装.net4.5,Win10怎么安装office免费版
- 拿什么拍摄,拍摄用什么软件
- 大型策略网络游戏,大型策略类网游
- vb.net比vb vbnet比vb6功能强大吗