timeformat trouble


Licensed User
I am playing with an application do get infos from hybrid cars from toyota,
to do this, I am using a BT interface from OBDLink, a service using Serial & AsyncStreams.
Alltogether, I am quite proud from my results and very satisfied from B4A, but I meet a strange problem with timeformat on asus transformer TF101 (not checked yet on other platforms).
one hour is added...
in a service whose name is "scanner", I have the following code:
Old_Ticker= Start_Ticker
New_Ticker= DateTime.Now
Trip_Time= New_Ticker - Start_Ticker
in the activity, I have the following code:
the strange thing, is I see for instance "01:00:06" instead of "00:00:06"
there is always one hour more.

I checked using log and the Trip_Time is ok;
example :
Start_Ticker= 1311437838853
Trip_Time= 6770 but we see it as "01:00:06"

Is there a relation with time offset to GMT????
I will check tomorrow if I get the same thing on a HTC HD


B4X founder
Staff member
Licensed User
DateTime.Time / Date / ParseTime / ParseDate are affected by the current time zone.

DateTime.Time isn't intended for showing a string representation of a time span.
It is intended to show the time of day represented by the number of milliseconds passed since 01/01/1970.
If the trip will be longer than 24 hours the value you will get will be completely wrong.
Instead I recommend you to convert the ticks (milliseconds) to a time string yourself.
Something like:
Sub ConvertToTimeFormat(ms As Long) As String
  Dim seconds, minutes, hours As Int     
  seconds = Round(ms / 1000)
  minutes = Floor(seconds / 60) Mod  60
  hours = Floor(seconds / 3600)
  seconds = seconds Mod 60
  Return NumberFormat(hours, 1, 0) & ":" & NumberFormat(minutes, 2, 0) & ":" & NumberFormat(seconds, 2, 0) 
End Sub


Licensed User
Instead I recommend you to convert the ticks (milliseconds) to a time string yourself.

Function that you gave works just fine.

Thanks a lot. It saved me lots of efforts.

Is there any function that convers 0:00:00 string to ms so that if i send this string to my timer control it starts time for same time instead of zero.

I know i am being lazy but its way to early in the morning here and do not have the energy to write it.

I will be greatful for your help.

regards and thanks in adv.