Android Code Snippet Convert timestamp date to Brasil format

Discussion in 'Code Snippets' started by Douglas Farias, Dec 4, 2018.

  1. Douglas Farias

    Douglas Farias Expert Licensed User

    Hi.
    here is a simple code to convert a timestamp to Brasil format, easy to modify to another countrys format.
    Code:
    Sub Timestamp_Brasileiro(dataTimeStamp As StringAs String
        
    DateTime.DateFormat = "yyyy-MM-dd" : DateTime.TimeFormat = "HH:mm:ss" 'TRANSFORMA DATA DO CEL EM PADRÃO DE BANCO DE DADOS
        Dim dataTempo() As String  = Regex.Split(" ", dataTimeStamp)
        
    Private ltempo As Long = DateTime.DateTimeParse(dataTempo(0),dataTempo(1))
        
    DateTime.DateFormat = "dd/MM/yyyy" : DateTime.TimeFormat = "HH:mm" 'VOLTAMOS A DATA PARA O PADRÃO BRASILEIRO
        Return DateTime.Date(ltempo) & " " & DateTime.Time(ltempo)
    End Sub
    Example of use
    Code:
    log(Timestamp_Brasileiro("2018-12-04 12:04:48"))
    the result log is
    04/12/2018 12:04

    ;)
     
    Jmu5667, fabricio and Merlot2309 like this.
  2. Jmu5667

    Jmu5667 Well-Known Member Licensed User

  3. Mahares

    Mahares Well Known Member Licensed User

    Why can't you just have something simple like this:
    Code:
    DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"
        
    Dim dt As Long =DateTime.DateParse("2018-12-04 12:04:48")
        
    DateTime.DateFormat = "dd/MM/yyyy HH:mm"
        
    Log($"$Date{dt}"$)  'displays: 04/12/2018 12:04
     
    Claudio Oliveira and DonManfred like this.
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