vb格式化时间问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 20:08:42
在VB中,如text1.text为17:3:2,我想把它格式化为17:03:02的形式,如何做到呢?

Dim Hours As Integer
Dim Minutes As Integer
Dim Seconds As Integer
Dim Time As Date
Hours = Val(Text1.Text)
Minutes = Val(Text2.Text)
Seconds = Val(Text3.Text)
Time = TimeSerial(Hours, Minutes, Seconds)
Label1.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")

text1.text=format(text1.text,"hh:mm:ss")