B4J Question Simple TimeDate.Time function not working ??

Noble

Member
Licensed User
Longtime User
Using B4J Ver. 6.30 jCore Lib 6.30

I'm trying to have a running time between ActionEvents (in Time format) and the current time (now).
I have added the Log statements to show the addition of 19 hours that I can't figure out where it is coming from.

ActionCounters(0-3,0) are stored with ticks from a current event (different part of the program).
This timer event is to calculate the difference in ticks from that event and now. Store in ActionCounters(0-3,1)
The calculation seems to be correct - from log below.
However, When I want to display the running time using DateTime.Time(ActionCounters(0-3,1)) function the time has an added 19 hours.
B4X:
Private Sub Timer1_Tick
    Log("Timer 1 Tick")
    Dim now As Long
    now = DateTime.Now
    For c = 0 To 3
        If  ActionCounters(c,0) > 100 Then
          ActionCounters(c,1) = now - ActionCounters(c,0)
          Log("Ticks for " & c & " is " & DateTime.Time(ActionCounters(c,1)))
          Log("Stored Time = " & DateTime.Time(ActionCounters(c,0)) & "  T=" & ActionCounters(c,0))
          Log("Time now    = " & DateTime.Time(now) & "  T=" & now)
          Log("Ticks difference = " & (now - ActionCounters(c,0)))
        Else
          Log("Empty")
        End If
    Next
    End Sub
The log results are:

Timer 1 Tick
Empty
Empty
Ticks for 2 is 19:00:04
Stored Time = 09:31:07 T=1530970267191
Time now = 09:31:11 T=1530970271889
Ticks difference = 4698
Ticks for 3 is 19:00:06
Stored Time = 09:31:04 T=1530970264976
Time now = 09:31:11 T=1530970271889
Ticks difference = 6913

As you can see the log line that shows "Ticks for 2" has an additional 19 hours added to the count.
the actual tick difference of 4698 looks correct.

Anyone know what is wrong here?
 
Last edited:

derez

Expert
Licensed User
Longtime User
Instead of using Datetime.Time which gives the time of day, divide the ticks difference by DateTime.TicksPerSecond to find the difference in seconds.
 
Upvote 0

Noble

Member
Licensed User
Longtime User
Thanks derez, the DateTime.TicksPerSecond got me another way around my problem and is working perfect now.
 
Upvote 0
Top