Hi all,
I am using DateUtlis to try to get the time period between 2 dates. I get the time period already in the ticks format and then I try to convert it into a time string so it displays something like 1 days 12 hours 29 minutes 51 seconds. Here is a code that I am currently using.
So the label text should appear as "1.12:29:51"
but when I get a large time period, something greater than 9 days for example, the hours value go past 24. Here is a example 9.214:18:4
So i suspect it is something to do with the Hours line inside the Sub but I cant figure out how to fix it. Can anyone help please?
I am using DateUtlis to try to get the time period between 2 dates. I get the time period already in the ticks format and then I try to convert it into a time string so it displays something like 1 days 12 hours 29 minutes 51 seconds. Here is a code that I am currently using.
B4X:
timeperiodlbl.text = (ConvertTicksToTimeString(ticks))
Sub ConvertTicksToTimeString(t As Long) As String
Dim days, hours, minutes, seconds As Int
days = t / DateTime.TicksPerDay
hours = t / DateTime.TicksPerHour
minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
Return NumberFormat(days, 2, 0) & "." _
& NumberFormat(hours, 2, 0) & ":" & NumberFormat(minutes, 2, 0) & ":" & NumberFormat(seconds, 2, 0) & ""
End Sub
So the label text should appear as "1.12:29:51"
but when I get a large time period, something greater than 9 days for example, the hours value go past 24. Here is a example 9.214:18:4
So i suspect it is something to do with the Hours line inside the Sub but I cant figure out how to fix it. Can anyone help please?