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
'三个部件:command1、text1和timer1
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
Text1.Text = ""
Command1.Caption = "开始"
End Sub
Private Sub Command1_Click()
Text1.Text = DateAdd("n", Text1.Text, "0:00")
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Text1.Text = DateAdd("s", -1, Text1.Text)
If Text1.Text = "00:00:00" Then Timer1.Enabled = False'若要用此语句,则系统时间格式必为“HH:mm:ss”
End Sub
数据类型中的日期型(Date)___取值范围:(100/1/1~9999/12/31)日期型数据专门用来处理日期和时间。VB采用一对“#”把日期和时间的值括起来,如#2003/08/20#表示2003年8月20日。
text1 = Format(67 \ 60 & ":" & 67 Mod 60 & ":00", "hh:mm:ss")
format(数值,"YYYY-MM-DD HH:MM:SS")