VB使用 CDate 函數(shù)將字符串轉換成 Date。
十多年的麻江網(wǎng)站建設經(jīng)驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。營銷型網(wǎng)站建設的優(yōu)勢是能夠根據(jù)用戶設備顯示端的尺寸不同,自動調(diào)整麻江建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“麻江網(wǎng)站設計”,“麻江網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
CDate 函數(shù)示例
本示例使用 CDate 函數(shù)將字符串轉換成
Date。一般說來,字符串格式的日期與時間硬編碼(如示例中所示)并不好。較好的做法是使用日期原義表達式和時間的原義表達式(如
#2/12/1969#,#4:45:23 PM#)。
Dim MyDate, MyShortDate, MyTime, MyShortTime
MyDate = "February 12, 1969" ' 定義日期。
MyShortDate = CDate(MyDate) ' 轉換為 Date 數(shù)據(jù)類型。
MyTime = "4:35:47 PM" ' 定義時間。
MyShortTime = CDate(MyTime) ' 轉換為 Date 數(shù)據(jù)類型。
vb把數(shù)值轉化為時間格式:
VB.net 中 取系統(tǒng)時間
Dim datestr As String = ""
datestr = Format(Now(), "yyyy/MM/dd H:mm:ss ffff")
用戶定義的日期/時間格式(Format 函數(shù))
轉化代碼:
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ù),這個函數(shù)是用于把字符型變量轉換成日期型變量,
字符型變量(本例中的a)如果不是標準的日期格式,請先用字符串函數(shù)處理成標準日期格式再用CDate函數(shù)進行轉換,否則會報錯
網(wǎng)頁題目:vb.net字串轉日期,c# 字符串轉化為日期
文章位置:http://chinadenli.net/article20/hescco.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站收錄、動態(tài)網(wǎng)站、網(wǎng)站導航、微信公眾號、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)