B4A Class Timeago. Display elapsed time between two dates/times

Discussion in 'Additional libraries, classes and official updates' started by Jerez, Aug 30, 2015.

  1. Jerez

    Jerez Active Member Licensed User

    Display elapsed time between two dates/times:

    Code:
    Sub Timeago(current As Long, previous As Long) As String 'params in ticks.
       
        
    Dim msPerMinute As Long = 60 * 1000
       
        
    Dim msPerHour As Long = msPerMinute * 60
       
        
    Dim msPerDay As Long = msPerHour * 24
       
        
    Dim msPerMonth As Long = msPerDay * 30
       
        
    Dim msPerYear As Long = msPerDay * 365

        
    Dim elapsed As Long = current - previous
       
        
    If (elapsed < msPerMinute) Then
           
             
    Return Round(elapsed/1000) & " seconds ago"
       
        
    else if (elapsed < msPerHour) Then
           
             
    Return Round(elapsed/msPerMinute) & " minutes ago"

        
    else if (elapsed < msPerDay ) Then
           
             
    Return Round(elapsed/msPerHour ) & " hours ago"  
       
        
    else if (elapsed < msPerMonth) Then
           
            
    Return "approximately " & Round(elapsed/msPerDay) & " days ago"
       
        
    else if (elapsed < msPerYear) Then
           
            
    Return "approximately " & Round(elapsed/msPerMonth) & " months ago" 
       
        
    Else
           
            
    Return "approximately " & Round(elapsed/msPerYear ) & " years ago"
           
        
    End If

    End Sub
     
    carlos7000 likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. MhdBoy

    MhdBoy Member Licensed User

    can you get an exam?
     
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