Android Code Snippet [B4X] Convert milliseconds to string

Erel

Administrator
Staff member
Licensed User
This code converts milliseconds to hours, minutes and seconds:

B4X:
Sub ConvertMillisecondsToString(t As Long) As String
   Dim hours, minutes, seconds As Int
   hours = t / DateTime.TicksPerHour
   minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
   seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
   Return $"$1.0{hours}:$2.0{minutes}:$2.0{seconds}"$
End Sub
It is somewhat similar to DateTime.Time however DateTime.Time works with ticks that represent a specific time instance and is therefore affected by the time zone.
 
Top