189 8069 5689

vb.net日期转换 vbnet format 日期

在VB.NET中如何将日期类型转化为String型?

在你对日期/时间进行格式化时,控制面板中的地区与语言选项部分的设置会影响你所得到的结果。那些设置用来初始化DateTimeFormatInfo对象,这个对象与当前线程的文化有关,并提供控制格式的值。

创新互联是一家集网站建设,雅安企业网站建设,雅安品牌网站建设,网站定制,雅安网站建设报价,网络营销,网络优化,雅安网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

Dim dateTimeInfo as DateTime = DateTime.Now

MessageBox.Show (dateTimeInfo)

Dim strMonth as String = dateTimeInfo.ToString("F")

MessageBox.Show(strMonth)

上面的代码定义了日期时间变量dateTimeInfo并将其值设为当前日期/时间。然后,我再定义字符串变量strMonth并将dateTimeInfo的值转换为"带长时间的完整日期/时间"格式下的字符串。

下面是一个标准日期格式说明符列表:

d:短日期

D:长日期

t:短时间

T:长时间

f:带短时间的完整日期/时间

F:带长时间的完整日期/时间

g:带短时间的一般日期/时间

G:带长时间的一般日期/时间

M或m:月-日

R或r:RFC1123

s:遵守ISO 8601的可分类日期/时间

u:国际可分类日期/时间

U:带长时间的完整日期/时间。(此格式与F相同,但它用于国际GMT时间。)

Y或y:年-月

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

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

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中怎么样将字符串类型转换成日期型

给你一个例子,里边包含了几种不同格式转换成标准的日期时间格式;

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

' 01/09/2001 00:00:00

Dim MyDateTime1 As DateTime = DateTime.Parse("Sep 2001")

' 05/09/2001 14:15:33

Dim MyDateTime2 As DateTime = DateTime.Parse("Wed 5 September 2001 14:15:33")

' 01/09/2005 00:00:00

Dim MyDateTime3 As DateTime = DateTime.Parse("5,9,01")

' 09/05/2001 14:15:33

Dim MyDateTime4 As DateTime = DateTime.Parse("5/9/2001 14:15:33")

' 当前系统日期 14:15:00

Dim MyDateTime5 As DateTime = DateTime.Parse("2:15 PM")

Dim MyInfo As String = MyDateTime1.ToString()

MyInfo += vbCrLf + MyDateTime2.ToString()

MyInfo += vbCrLf + MyDateTime3.ToString()

MyInfo += vbCrLf + MyDateTime4.ToString()

MyInfo += vbCrLf + MyDateTime5.ToString()

MessageBox.Show(MyInfo, "信息提示", _

MessageBoxButtons.OK, MessageBoxIcon.Information)

Catch ex As Exception

MessageBox.Show(ex.Message, "信息提示", _

MessageBoxButtons.OK, MessageBoxIcon.Information)

End Try

End Sub

End Class

vb.net中如何获取当前日期所在星期的星期一的具体年月日

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

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如何把数值转化为时间格式

vb把数值转化为时间格式:

VB.net 中 取系统时间

Dim datestr As String = ""

datestr = Format(Now(), "yyyy/MM/dd H:mm:ss ffff")

用户定义的日期/时间格式(Format 函数)

转化代码:

Dim t As Integer, t1 As Integer, t2 As Integer, s As String

Dim tim As Date

Dim i As Integer, j As Integer

Private Sub Command1_Click()

s = InputBox("分钟数:", "输入", 67)

If s = "" Then Exit Sub

t = Val(s)

If t = 0 Then Exit Sub

t1 = t \ 60

t2 = t Mod 60

s = t1 ":" t2

tim = Format(s, "hh:mm:ss")

Text1.Text = tim

Timer1.Interval = 1000

Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

Dim tt1 As Integer, tt2 As Integer, tt3 As Integer, tt As String

tt = Text1.Text

tt1 = Val(Left(tt, Len(tt) - 6))

tt2 = Val(Mid(tt, Len(tt) - 4, 2))

tt3 = Val(Right(tt, 2))

tt3 = tt3 - 1

If tt3 0 Then tt3 = 59: tt2 = tt2 - 1

If tt2 0 Then tt2 = 59: tt1 = tt1 - 1

If tt1 0 Then Timer1.Enabled = False: Exit Sub

tt = tt1 ":" tt2 ":" tt3

tim = Format(tt, "hh:mm:ss")

Text1.Text = tim

End Sub

vb.net中日期类型怎么从字符串转换

Dim a As String

Dim b As Date

a = "2016-11-18"

b = CDate(a)

本例中最主要的就是CDate()函数,这个函数是用于把字符型变量转换成日期型变量,

字符型变量(本例中的a)如果不是标准的日期格式,请先用字符串函数处理成标准日期格式再用CDate函数进行转换,否则会报错


网页标题:vb.net日期转换 vbnet format 日期
URL地址:http://cdxtjz.com/article/hhjcjg.html

其他资讯