How do you parse a millisecond number into HH:MM:SS ?

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Can you tell me how to parse a millisecond number such as 10173510 into hours, minutes and seconds?

Formated like this maybe?
HH:MM:SS

Thanks.
 
Last edited:

rleiman

Well-Known Member
Licensed User
Longtime User
Hi NJDude,

Thanks for the reply.

I looked at that and tried this code:

B4X:
Sub SeekBarTimeToKeepActive_ValueChanged (Value As Int, UserChanged As Boolean)
   
   Dim intHoursToKeepActive As Int
   Dim intMinutesToKeepActive As Int
   Dim intSecondsToKeepActive As Int

   intHoursToKeepActive = DateTime.GetHour(Value)
   intMinutesToKeepActive = DateTime.GetMinute(Value)
   intSecondsToKeepActive = DateTime.GetSecond(Value)

   LabelTimeToKeepActive.Text = "Length of time to keep active: " & _
      intHoursToKeepActive & ":" & intMinutesToKeepActive & ":" & intSecondsToKeepActive
End Sub

I think I'm missing something here because the numbers returned are not what I thought. I set the seekbar maximum value as 3600000 which should be 1 hour. The values started with 19 hours and end with 20 hours. It looks like the minutes and seconds are ok for the time span as the minutes start at 0 and increase until they become 0 again.

What did I do wrong with the hours? Should I just subtract 19 from this before displaying it?
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
I'm getting closer. Here is the code I'm now using:

B4X:
Sub SeekBarTimeToKeepActive_ValueChanged (Value As Int, UserChanged As Boolean)
   
   Dim intHoursToKeepActive As Int
   Dim intMinutesToKeepActive As Int
   Dim intSecondsToKeepActive As Int

   intHoursToKeepActive = DateTime.GetHour(Value) -19
   intMinutesToKeepActive = DateTime.GetMinute(Value)
   intSecondsToKeepActive = DateTime.GetSecond(Value)

   LabelTimeToKeepActive.Text = "Length of time to keep active: " & _
      intHoursToKeepActive & ":" & intMinutesToKeepActive & ":" & intSecondsToKeepActive
End Sub

This will return a result like: 1:3:52

Can you tell me how to format it to look like: 01:03:52 ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Search for NumberFormat, it'll be at the top of the results list.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Here is my final coding to get it looking good:

B4X:
Sub SeekBarTimeToKeepActive_ValueChanged (Value As Int, UserChanged As Boolean)
   
   Dim intHoursToKeepActive As Int
   Dim intMinutesToKeepActive As Int
   Dim intSecondsToKeepActive As Int

   intHoursToKeepActive = DateTime.GetHour(Value) -19
   intMinutesToKeepActive = DateTime.GetMinute(Value)
   intSecondsToKeepActive = DateTime.GetSecond(Value)

   LabelTimeToKeepActive.Text = "Active for this long: " & _
      NumberFormat(intHoursToKeepActive, 2, 0) & ":" & _
      NumberFormat(intMinutesToKeepActive, 2, 0) & ":" & _
      NumberFormat(intSecondsToKeepActive, 2, 0)
End Sub

Thanks everyone for the help.
 
Upvote 0
Top