包含vbnet取时间戳的词条-成都快上网建站

包含vbnet取时间戳的词条

vb.net中怎么获取日期中的年月日时分秒

Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '获得当前日期字符串

创新互联公司专注于企业网络营销推广、网站重做改版、丰泽网站定制设计、自适应品牌网站建设、H5网站设计电子商务商城网站建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为丰泽等各大城市提供网站开发制作服务。

Dim ThisDateTime As DateTime = Convert.ToDateTime(ThisDay) '当前日期转换成DateTime

Dim ThisWeekDay As Integer = ThisDateTime.DayOfWeek '获得当前日期是星期几

Dim differadd As Integer = 1 - ThisWeekDay '相差的天数(星期1与当前星期几相差的天数)

Dim MyAdd As New TimeSpan(differadd, 0, 0, 0)

Dim MyYear As Integer = Format(Now, "yyyy") '获取当前日期的年份

Dim MyMonth As Integer = Format(Now, "MM") '获取当前日期的月份

Dim MyDay As Integer = Format(Now, "dd") '获取当前日期是几号

Dim MyToday As DateTime = New DateTime(MyYear, MyMonth, MyDay)

Dim Yourday As DateTime = MyToday.Add(MyAdd)

MsgBox("本周星期一的日期是:" Yourday)

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 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.CtlState MSWinsockLib.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 = MyDate Space(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 = 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

vb.net 如何将时间戳转化为date类型

Dim unix As DateTime = #1/1/1970#

unix = unix.AddSeconds(CDbl("时间戳"))

MsgBox(unix)

'--------------------

百度VB2010(VB.NET)吧建设发展中,需要你的支持和帮助!!!

快加入我们吧!发表你的疑问,经验,程序,分享..

让我们共同进步!

vb net获取系统时间

Sub gettime()

nowtime = Format(DateTime.Now, "yyyy/MM/dd hh:mm:ss")

MsgBox nowtime

End Sub

其中DateTime.Now为当前系统的时间

Format是设置时间格式

效果如下

vb 时间戳转换成时间

VB可使用DateAdd 函数来获取加上了一段时间间隔后的日期和时间数据。

DateAdd 函数,返回包含一个日期的 Variant

(Date),这一日期还加上了一段时间间隔。

代码实例:

Private Sub Command1_Click()

Dim D As Date

Dim Sj As Long

Sj = InputBox("输入秒数:", Sj)

D = DateAdd("s", Sj, #1/1/1970#)

Debug.Print D

End Sub


网站栏目:包含vbnet取时间戳的词条
网站路径:http://kswjz.com/article/dsiehsd.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流