十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
假设你得到 N 秒
专业领域包括网站制作、网站设计、商城网站建设、微信营销、系统平台开发, 与其他网站设计及系统开发公司不同,成都创新互联公司的整合解决方案结合了帮做网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,为客户提供全网互联网整合方案。
那么,一个小时就是 3600 秒,一分钟就是 60 秒,我们就可以这样子分割出来 :
小时 hour = N / 3600;
分钟 minute = ( N - ( hour * 3600 ) ) / 60;
秒 second = N - ( hour * 3600 + minute * 60 );
然后自己按照 hour : minute : second 的格式打印出来就行了 。
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。
Public Class Form1
Private Past As Date
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Past = Now
IO.File.AppendAllText("test.txt", Past.ToString, System.Text.Encoding.Default)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Now1 As Date = CDate(IO.File.ReadAllText("test.txt", System.Text.Encoding.Default))
Dim Now2 As Date = Now
MsgBox("从" Now1.ToString "到" Now2.ToString "经过了" CStr(CDate((Now2 - Now1).ToString)))
End Sub
实际情况修改下。
End Class
是我以前自己设计的用来测试自己点钞速度用的,希望是你需要的
以下是窗体的全部代码
Public Class Form1
Dim StartFlag As Boolean = False
Dim secon As Integer
Dim minut As Integer
'空格
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Space Then
If StartFlag Then
StartFlag = False
Timer1.Enabled = False
If Val(Strings.Right(Label1.Text, 2)) 10 And Val(Strings.Right(Label1.Text, 2)) = 0 Then secon = 0 : minut = 0 : Label1.Text = "00:00" : Exit Sub
ListBox1.Items.Add(Label1.Text.ToString)
ListBox1.SelectedItem = ListBox1.Items.Count - 1
Label1.Focus()
Button1.Enabled = True
Label1.Text = "00:00"
secon = 0
minut = 0
Else
StartFlag = True
Timer1.Enabled = True
End If
End If
End Sub
'加载
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Clear()
Label1.Text = "00:00"
Button1.Enabled = False
secon = 0
minut = 0
Label1.Focus()
End Sub
'清空
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Enabled = False
ListBox1.Items.Clear()
Label1.Focus()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
secon += 1
If secon = 60 Then
secon = 0
minut += 1
End If
Dim seconStr As String = secon
If seconStr.Length = 1 Then seconStr = "0" + seconStr
Dim minutStr As String = minut
If minutStr.Length = 1 Then minutStr = "0" + minutStr
Label1.Text = minutStr + ":" + seconStr
Label1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SeconSun As Integer
If ListBox1.Items.Count 0 Then
For i = 0 To ListBox1.Items.Count - 1
Dim TemStr As String = ListBox1.Items.Item(i).ToString
Dim TemInt1 As Integer = Val(Strings.Right(TemStr, 2))
Dim TemInt2 As Integer = Val(Strings.Left(TemStr, 2))
Debug.Print(TemInt1.ToString)
Debug.Print(TemInt2.ToString)
SeconSun += TemInt1 + TemInt2 * 60
Debug.Print(SeconSun.ToString)
Next
TextBox1.Text = (SeconSun / ListBox1.Items.Count).ToString + "秒"
End If
Label1.Focus()
End Sub
End Class