Android Code Snippet [B4X] Convert milliseconds to string

Discussion in 'Code Snippets' started by Erel, Feb 22, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This code converts milliseconds to hours, minutes and seconds:

    Code:
    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice