vb.net获取年,月,日,时,分,秒不是 有 函数嘛?
now() 就是 吧
取得 后 再 分离出你所需的,分别赋值 就行了 , 当然 还是 有 函数的
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 = sDateTime.Today.Month()
s = sDateTime.Today.Day()
s = sDateTime.Now.Hour()
s = sDateTime.Now.Minute()
s = sDateTime.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())
【vb.net获取时间戳的简单介绍】End Sub
Vb.net 2008 如何获取网络时间你是指Internet上的国际标准时间吗 。
先加入控件 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.gov!")
Else
NetTime("time.nist.gov")
If TimeFromNet = "" Then
MsgBox("网络标准时间服务器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 = MyDateSpace(1)NewTime
MsgBox(MyTime)
'SetWindowsClock(MyTime)
End If
End If
Else
'使网络误差时间小 , 第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
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中用label显示时间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
vb.net获取时间戳的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、vb.net获取时间戳的信息别忘了在本站进行查找喔 。
推荐阅读
- 飞行stg街机游戏,早期飞行街机游戏大全
- 关于快手如何开拓海外市场营销的信息
- 什么是弧形拍摄方法,什么是弧形拍摄方法图片
- mysql先写数据库还是binlog,数据库是先输入数据再建立数据库的结构吗
- mysql怎么设置字段 mysql怎么设置字段的取值只能为教授副教授
- html支付alipayhtml5app,HTML支付功能怎么实现
- 戴尔重装系统用u盘怎么装,戴尔u盘系统重装教程
- 鸿蒙免费可交互桌面主题,鸿蒙主题免费教程
- linux命令行如何进入 linux命令行如何进入管理员模式