我试图让vb.net显示以hh:mm:ss格式运行的运行时间。我想让它在几秒钟内显示我能获得帮助吗? 因此,例如,如果它是10:00:00 am,那么那将是10 * 60 * 60.但是时间会自动继续,如果时间是10:19:23 am那么我该怎么办?
我的代码:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label2.Text = Format(Now, "HH:mm:ss")
End Sub
Private Function GetSeconds(ByVal timestamp As DateTime) As Integer
Dim timespan As TimeSpan = Now - timestamp
Return (timespan.TotalSeconds)
End Function
答案 0 :(得分:2)
以下几种方式可以在几秒钟内获得时间:
Dim a As Double = Now.TimeOfDay.TotalSeconds ' 39715.561210299995
Dim b As Long = TimeOfDay.Ticks \ 10000000 ' 39715
Dim c As Double = TimeOfDay.ToOADate * 24 * 60 * 60 ' 39715.000000000007
Dim d As Double = (Now.ToOADate Mod 1) * 24 * 60 * 60 ' 39715.000000000007