重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Option Explicit
成都创新互联公司主营奉化网站建设的网络公司,主营网站建设方案,成都app软件开发,奉化h5重庆小程序开发搭建,奉化网站营销推广欢迎奉化等地区企业咨询
Dim Times As String, T As Long
Dim D As Integer, H As Integer, M As Integer, S As Integer
Private Sub Form_Load()
Form1.AutoRedraw = True
Times = InputBox("输入时间(单位:秒)", "输入", 123456)
T = Val(Times)
S = T Mod 60
T = T \ 60
M = T Mod 60
T = T \ 60
H = T Mod 24
D = T \ 24
Print Val(Times); "秒="; D; "日"; H; "时"; M; "分"; S; "秒"
End Sub
Public Class Form1
Private Function ZToFSAll(ByVal ZT As Long) As String
'全存样式
'从天,时,分,秒整合为秒
Dim T, S, F, M As Integer '天,时,分,秒
Dim T1, S1 As Integer '天,时,分,秒
Dim M1 As String
T = ZT \ 86400
T1 = ZT Mod 86400
S = T1 \ 3600
S1 = T1 Mod 3600
F = S1 \ 60
M = S1 Mod 60
If M 10 Then
M1 = "0" M
Else
M1 = M
End If
ZToFSAll = T "天" S "小时" F "分钟" M1 "秒"
End Function
Private Function ZToFSQS(ByVal ZT As Long) As String
'缺损样式
'从秒分解为天,时,分,秒
Dim T, S, F, M As Integer '天,时,分,秒
Dim T1, S1 As Integer '天,时,分,秒
Dim T2, S2, F2, M2 As String '天,时,分,秒
T = ZT \ 86400
T1 = ZT Mod 86400
S = T1 \ 3600
S1 = T1 Mod 3600
F = S1 \ 60
M = S1 Mod 60
If T = 0 Then
T2 = ""
Else
T2 = T "天"
End If
If S = 0 Then
S2 = ""
Else
S2 = S "小时"
End If
If F = 0 Then
F2 = ""
Else
F2 = F "分钟"
End If
M2 = M "秒"
ZToFSQS = T2 S2 F2 M2
End Function
Private Function FSoZT(ByVal T As Integer, ByVal S As Int16, ByVal F As Int16, ByVal M As Int16) As Long
'从天,时,分,秒分解为秒
'T, S, F, M分别为天,时,分,秒
FSoZT = T * 86400 + S * 3600 + F * 60 + M
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ZToFSQS(520354) '值为:6天32分钟34
TextBox1.Text = ZToFSAll(520354) '值为:6天0小时32分钟34秒
TextBox1.Text = FSoZT(6, 0, 32, 34) '值为:520354
End Sub。
Dim day As Integer, hour As Integer, minute As Integer, second As Integer, temp As Integer
temp = Val(TextBox.Text)
second = temp Mod 60
temp = (temp - second) / 60
minute = temp Mod 60
temp = (temp - minute) / 60
hour = temp Mod 24
day = (temp - hour) / 24
MsgBox Str(day) "天" hour "小时" minute "分" second "秒"
假设你得到 N 秒
那么,一个小时就是 3600 秒,一分钟就是 60 秒,我们就可以这样子分割出来 :
小时 hour = N / 3600;
分钟 minute = ( N - ( hour * 3600 ) ) / 60;
秒 second = N - ( hour * 3600 + minute * 60 );
然后自己按照 hour : minute : second 的格式打印出来就行了 。