在你對(duì)日期/時(shí)間進(jìn)行格式化時(shí),控制面板中的地區(qū)與語言選項(xiàng)部分的設(shè)置會(huì)影響你所得到的結(jié)果。那些設(shè)置用來初始化DateTimeFormatInfo對(duì)象,這個(gè)對(duì)象與當(dāng)前線程的文化有關(guān),并提供控制格式的值。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),雅安企業(yè)網(wǎng)站建設(shè),雅安品牌網(wǎng)站建設(shè),網(wǎng)站定制,雅安網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,雅安網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
Dim dateTimeInfo as DateTime = DateTime.Now
MessageBox.Show (dateTimeInfo)
Dim strMonth as String = dateTimeInfo.ToString("F")
MessageBox.Show(strMonth)
上面的代碼定義了日期時(shí)間變量dateTimeInfo并將其值設(shè)為當(dāng)前日期/時(shí)間。然后,我再定義字符串變量strMonth并將dateTimeInfo的值轉(zhuǎn)換為"帶長時(shí)間的完整日期/時(shí)間"格式下的字符串。
下面是一個(gè)標(biāo)準(zhǔn)日期格式說明符列表:
d:短日期
D:長日期
t:短時(shí)間
T:長時(shí)間
f:帶短時(shí)間的完整日期/時(shí)間
F:帶長時(shí)間的完整日期/時(shí)間
g:帶短時(shí)間的一般日期/時(shí)間
G:帶長時(shí)間的一般日期/時(shí)間
M或m:月-日
R或r:RFC1123
s:遵守ISO 8601的可分類日期/時(shí)間
u:國際可分類日期/時(shí)間
U:帶長時(shí)間的完整日期/時(shí)間。(此格式與F相同,但它用于國際GMT時(shí)間。)
Y或y:年-月
Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '獲得當(dāng)前日期字符串
Dim ThisDateTime As DateTime = Convert.ToDateTime(ThisDay) '當(dāng)前日期轉(zhuǎn)換成DateTime
Dim ThisWeekDay As Integer = ThisDateTime.DayOfWeek '獲得當(dāng)前日期是星期幾
Dim differadd As Integer = 1 - ThisWeekDay '相差的天數(shù)(星期1與當(dāng)前星期幾相差的天數(shù))
Dim MyAdd As New TimeSpan(differadd, 0, 0, 0)
Dim MyYear As Integer = Format(Now, "yyyy") '獲取當(dāng)前日期的年份
Dim MyMonth As Integer = Format(Now, "MM") '獲取當(dāng)前日期的月份
Dim MyDay As Integer = Format(Now, "dd") '獲取當(dāng)前日期是幾號(hào)
Dim MyToday As DateTime = New DateTime(MyYear, MyMonth, MyDay)
Dim Yourday As DateTime = MyToday.Add(MyAdd)
MsgBox("本周星期一的日期是:" Yourday)
給你一個(gè)例子,里邊包含了幾種不同格式轉(zhuǎn)換成標(biāo)準(zhǔn)的日期時(shí)間格式;
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")
' 當(dāng)前系統(tǒng)日期 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
Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '獲得當(dāng)前日期字符串
Dim ThisDateTime As DateTime = Convert.ToDateTime(ThisDay) '當(dāng)前日期轉(zhuǎn)換成DateTime
Dim ThisWeekDay As Integer = ThisDateTime.DayOfWeek '獲得當(dāng)前日期是星期幾
Dim differadd As Integer = 1 - ThisWeekDay '相差的天數(shù)(星期1與當(dāng)前星期幾相差的天數(shù))
Dim MyAdd As New TimeSpan(differadd, 0, 0, 0)
Dim MyYear As Integer = Format(Now, "yyyy") '獲取當(dāng)前日期的年份
Dim MyMonth As Integer = Format(Now, "MM") '獲取當(dāng)前日期的月份
Dim MyDay As Integer = Format(Now, "dd") '獲取當(dāng)前日期是幾號(hào)
Dim MyToday As DateTime = New DateTime(MyYear, MyMonth, MyDay)
Dim Yourday As DateTime = MyToday.Add(MyAdd)
MsgBox("本周星期一的日期是:" Yourday)
vb把數(shù)值轉(zhuǎn)化為時(shí)間格式:
VB.net 中 取系統(tǒng)時(shí)間
Dim datestr As String = ""
datestr = Format(Now(), "yyyy/MM/dd H:mm:ss ffff")
用戶定義的日期/時(shí)間格式(Format 函數(shù))
轉(zhuǎn)化代碼:
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("分鐘數(shù):", "輸入", 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
Dim a As String
Dim b As Date
a = "2016-11-18"
b = CDate(a)
本例中最主要的就是CDate()函數(shù),這個(gè)函數(shù)是用于把字符型變量轉(zhuǎn)換成日期型變量,
字符型變量(本例中的a)如果不是標(biāo)準(zhǔn)的日期格式,請先用字符串函數(shù)處理成標(biāo)準(zhǔn)日期格式再用CDate函數(shù)進(jìn)行轉(zhuǎn)換,否則會(huì)報(bào)錯(cuò)
網(wǎng)站欄目:vb.net日期轉(zhuǎn)換 vbnet format 日期
轉(zhuǎn)載注明:http://chinadenli.net/article26/hhjcjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、ChatGPT、營銷型網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、虛擬主機(jī)、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)