Time interval

petrbury

Member
Licensed User
Longtime User
Hi,
I have a problem with counting the time interval. I'm trying to count, how much time is between two events in my software, but I'm not succesful.
For example in this code
B4X:
        TimeFormat("hh:mm:ss")
   Time1 = "09:00:00"
   Time2 = "09:00:06"
   Ticks1 = TimeParse(Time1)
   Ticks2 = TimeParse(Time2)
   T = Ticks2 - Ticks1
   DeltaT = Time(T)
the result is 12:00:06 and not 00:00:06 as I would expect.
What am I doing wrong ?
Thanks Petr.
 

klaus

Expert
Licensed User
Longtime User
You must use 24 hours format:
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]TimeFormat[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"HH:mm:ss"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/SIZE][/FONT]

instead of 12 hours format
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]TimeFormat[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"hh:mm:ss"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/SIZE][/FONT]

In 12 hours format time begins with 12:00:00PM
In 24 hours format time begins with 00:00:00

Best regards.
 

corwin42

Expert
Licensed User
Longtime User
Be aware that measuring time with b4ppc is very inaccurate on the device. If you want to measure intervals smaller than 1 second you should use GetTickCount from dzhw.library.

Greetings,
Markus
 
Top