lngS = Val(Text1.Text) Debug.Print DateAdd("s", lngS, 0) End Sub
~,给你个笨办法,手动改,我就这么用的,知道有专门的函数,但不清楚是哪个,又不用怎么讲究效率,就这么用了Dim Tp As String Dim h, m, s As Integer Dim t As String Tp = Text1.Text h = Tp \ 3600 m = (Tp Mod 3600) \ 60 s = (Tp Mod 3600) Mod 60 t = Trim(Format(Str(h), "00") & ":" & Format(Str(m), "00") & ":" & Format(Str(s), "00")) Debug.Print t
这样更完美了!否则会本来间隔是0时会变成12时的 Private Sub Command1_Click() Dim lngS As Long lngS = Val(Text1.Text) Me.Caption = Format(DateAdd("s", lngS, 0), "hh" & "时" & "nn" & "分" & "ss" & "秒") End Sub
Option Explicit Private Function funSecondToMin(ByVal lngSec As Long) As String Dim strP As String On Error GoTo errSub funSecondToMin = "0:00" strP = CStr(lngSec \ 60) & ":" & Right("00" & (lngSec Mod 60), 2) funSecondToMin = strP Exit Function errSub:End Function Private Sub btnConvert_Click() txtMinAndSecond.Text = funSecondToMin(Val(txtSecond.Text)) End SubPrivate Sub Form_Load() txtSecond.Text = "1000" txtMinAndSecond.Text = "" End Sub
Dim lngS As Long
lngS = Val(Text1.Text)
Debug.Print DateAdd("s", lngS, 0)
End Sub
Dim h, m, s As Integer
Dim t As String
Tp = Text1.Text
h = Tp \ 3600
m = (Tp Mod 3600) \ 60
s = (Tp Mod 3600) Mod 60
t = Trim(Format(Str(h), "00") & ":" & Format(Str(m), "00") & ":" & Format(Str(s), "00"))
Debug.Print t
Private Sub Command1_Click()
Dim lngS As Long
lngS = Val(Text1.Text)
Me.Caption = Format(DateAdd("s", lngS, 0), "hh" & "时" & "nn" & "分" & "ss" & "秒")
End Sub
Private Function funSecondToMin(ByVal lngSec As Long) As String
Dim strP As String
On Error GoTo errSub
funSecondToMin = "0:00"
strP = CStr(lngSec \ 60) & ":" & Right("00" & (lngSec Mod 60), 2)
funSecondToMin = strP
Exit Function
errSub:End Function
Private Sub btnConvert_Click()
txtMinAndSecond.Text = funSecondToMin(Val(txtSecond.Text))
End SubPrivate Sub Form_Load()
txtSecond.Text = "1000"
txtMinAndSecond.Text = ""
End Sub
msgbox TimeSerial(0, a \ 60, a Mod 60)放到秒那里会有可能溢出,放在分钟就不会了
在我电脑上显示上午 01:01:28