Android Question converting seconds in hh:mm:ss

Discussion in 'Android Questions' started by rleiman, Jan 1, 2014.

  1. rleiman

    rleiman Well-Known Member Licensed User

    Hi Everyone,

    Has anyone mad a function that allows the programmer to pass seconds into it and have it return just the seconds portion?

    For exaple, a function called fcnNumberOfSeconds:

    Sub fcnNumberOfSeconds (intSeconds As Int) As Int
    Dim intReturnValue As Int = 0
    ' Code to extract just the seconds from the number passed in.
    Return intReturnValue
    End Sub
    Let's say the number passed to it is 95 which is 1 minute 35 seconds. I'm looking for the function to return the number 35.

    Does B4A have a time function that does this?
  2. stevel05

    stevel05 Expert Licensed User

    how about
    95 Mod 60
    MarcoRome, Erel and thedesolatesoul like this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    You can use this code:
    Sub ConvertTicksToTimeString(t As Long) As String
    Dim  hours, minutes, seconds As Int
        hours = t / 
        minutes = (t 
    Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
        seconds = (t 
    Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
    Return NumberFormat(hours, 20) & " hours, " _
    NumberFormat(minutes, 20) & " minutes and " & NumberFormat(seconds, 20) & " seconds"
    End Sub
    Dim ticks As Long = 95 * DateTime.TicksPerSecond
    fredo, eps, MarcoRome and 1 other person like this.
  4. rleiman

    rleiman Well-Known Member Licensed User

    Hi Erel,

    Thanks for the helpful function. :D
  5. Marcos Alves

    Marcos Alves Active Member Licensed User

    for minute:second only use:

    Sub ConvertTicksToTimeString(t As Long) As String
    Dim  minutes, seconds As Int

        minutes = t/
        seconds = t - minutes * 
    Return NumberFormat(minutes, 20) & ":" & NumberFormat(seconds, 20)
    End Sub
    ShaneG30 and rleiman like this.
  6. rleiman

    rleiman Well-Known Member Licensed User

    Hi Marcos,

    Thanks for the function.
  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