Android Question ISO8601 painful parsing

Discussion in 'Android Questions' started by peacemaker, Apr 18, 2019.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    HI, All

    Is there any standard class or function that for sure can parse this garbage ?
    Million variants of formatting, from various programming languages, libs....
    Does Java have some standard function to get the ticks from any ISO8601 string ?

    Please, no need any parsing code - i have seen tons already.

    p.s. trouble is with string like "2019-04-17T22:45:05.6271501+03:00" - that is ... 7 digits after dot... that is from some JavaScript lib...
    And seems, if the latest zero exists - it's avoided. So - is it 8 digits can be ?!?
    All this means that the string format is not fixed, and always special parsing is required ?!
     
    Last edited: Apr 18, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
     
    Log(DateTime.DateParse(RemoveMilliseconds("2019-04-17T22:45:05.2301+03:00")))

    Sub RemoveMilliseconds (s As StringAs String
       
    Return Regex.Replace("\.\d+", s, "")
    End Sub
     
    peacemaker likes this.
  3. peacemaker

    peacemaker Well-Known Member Licensed User

    Thanks, Erel, for the elegant solution !
    But as the subject - no any standard function in Java itself ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    No.
     
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