Help Turn a Uint64 into Hours:Minutes:Seconds  
Author Message
Joshizzle





PostPosted: Visual Basic Language, Help Turn a Uint64 into Hours:Minutes:Seconds Top

Ok, so I have a timer adding 1000 to a variable called Online.

Online is a UInt64

How can I turn it into Hours:Minutes:Seconds

Like 03:23:25



Visual Basic16  
 
 
Tall Dude





PostPosted: Visual Basic Language, Help Turn a Uint64 into Hours:Minutes:Seconds Top

How about something like this:

Public Class Form1

Dim start As Date

Dim diff As New TimeSpan

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

Timer1.Enabled = True

start = Now

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Timer1.Tick

diff = Now - start

Label1.Text = diff.ToString

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click

Timer1.Enabled = False

End Sub

End Class



 
 
DMan1





PostPosted: Visual Basic Language, Help Turn a Uint64 into Hours:Minutes:Seconds Top

Dim Online As UInt64 = 456789000 'milliseconds

Dim iOnline As Int64 = Convert.ToInt64(Online)

'convert to increment of 100 nanoseconds for timespan

iOnline = CLng((iOnline * (10 ^ 6)) / 100)

Dim ts As New TimeSpan(iOnline)

Debug.Print(("{0} Days {1} Hours, {2} Min, {3} Seconds"), ts.Days, ts.Hours, ts.Minutes, ts.Seconds)



 
 
Joshizzle





PostPosted: Visual Basic Language, Help Turn a Uint64 into Hours:Minutes:Seconds Top

This resets to 00:00:00 after 25 hours... How do I fix it


 
 
DMan1





PostPosted: Visual Basic Language, Help Turn a Uint64 into Hours:Minutes:Seconds Top

What resets...and what code are you using

If you are talking about the TimeSpans hours property then yes....the valid range of that property is from -23 to +23...if you are wanting NOT to include days then use the timespans TotalHours property instead

ts.TotalHours:tsMinutes:ts.Seconds



 
 
Joshizzle





PostPosted: Visual Basic Language, Help Turn a Uint64 into Hours:Minutes:Seconds Top

im doing

Dim iOnline As Int64 = Convert.ToInt64(Online)

'convert to increment of 100 nanoseconds for timespan

iOnline = CLng((iOnline * (10 ^ 6)) / 100)

Dim ts As New TimeSpan(iOnline)



me.text = "<Online " & String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds) & ">"

and its fine until it gets to 25 hours..


I need this to be able to count up to 100's of hours


 
 
DMan1





PostPosted: Visual Basic Language, Help Turn a Uint64 into Hours:Minutes:Seconds Top

Change ts.Hours to ts.TotalHours

me.text = "<Online " & String.Format("{0:00}:{1:00}:{2:00}", ts.TotalHours, ts.Minutes, ts.Seconds) & ">"