VB.net 中如何将秒数转换为分钟或者小时
假设你得到 N 秒
10年积累的做网站、成都网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有蚌山免费网站建设让你可以放心的选择与我们合作。
那么,一个小时就是 3600 秒,一分钟就是 60 秒,我们就可以这样子分割出来 :
小时 hour = N / 3600;
分钟 minute = ( N - ( hour * 3600 ) ) / 60;
秒 second = N - ( hour * 3600 + minute * 60 );
然后自己按照 hour : minute : second 的格式打印出来就行了 。
VB.NET 如何将秒转化为小时,分钟,秒的形式
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。
计算0时0分到当前时间的秒数差,vb.net代码应该怎么写?
Sub Main()
Dim dtNow As DateTime
dtNow = DateTime.Now
Dim dtBegin As DateTime
dtBegin = New DateTime(dtNow.Year, dtNow.Month, dtNow.Day)
Dim second As Integer
second = (dtNow - dtBegin).TotalSeconds
Console.WriteLine(second)
Console.Read()
End Sub
网站标题:vb.net时间秒数的简单介绍
本文路径:http://scgulin.cn/article/dddeddd.html