Karthik Nandula
Karthik Nandula

Reputation: 73

How can I get hh:mm:ss to display in just seconds in vb.net

I have tried to get vb.net to display the running time which worked in the format hh:mm:ss. I want to get it to display in just seconds could I get help? So for example if it was 10:00:00 am, then that would be 10 * 60 * 60. However the time would automatically continue and if say the time was 10:19:23 am then what would I do?

My code:

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

Upvotes: 1

Views: 2785

Answers (1)

Slai
Slai

Reputation: 22876

Here are few ways to get the time of day in seconds:

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

Upvotes: 3

Related Questions