在你对日期/时间进行格式化时,控制面板中的地区与语言选项部分的设置会影响你所得到的结果.那些设置用来初始化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:月-日
u:国际可分类日期/时间
U:带长时间的完整日期/时间.(此格式与F相同,但它用于国际GMT时间.)
Y或y:年-月
Dim d As Double
d = CDbl(日期时间变量)
时间相差1秒,数值却相差十万八千里!
vb把数值转化为时间格式:
VB.net 中 取系统时间
Dim datestr As String = ""
datestr = Format(Now(), "yyyy/MM/dd H:mm:ss ffff")
用户定义的日期/时间格式(Format 函数)
转化代码:
Dim tim As Date
Dim i As Integer, j As Integer
Private Sub Command1_Click()
?If s = "" Then Exit Sub
?t = Val(s)
?If t = 0 Then Exit Sub
?tim = Format(s, "hh:mm:ss")
?Text1.Text = tim
?Timer1.Interval = 1000
?Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
?tt = Text1.Text
?If tt1 0 Then Timer1.Enabled = False: Exit Sub
?tim = Format(tt, "hh:mm:ss")
把当前时间转为双精度值:
Dim n As Double
n = Now
或者直接用
n = CDbl(Now)
所以你可以用 cdbl 转换成 double 就可以了
Dim a As String
Dim b As Date
b = CDate(a)
本例中最主要的就是CDate()函数,这个函数是用于把字符型变量转换成日期型变量,
字符型变量(本例中的a)如果不是标准的日期格式,请先用字符串函数处理成标准日期格式再用CDate函数进行转换,否则会报错
以上就是土嘎嘎小编为大家整理的vb.net日期转数值相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!