Android Question ISO8601 time zone

Discussion in 'Android Questions' started by peacemaker, Sep 6, 2018.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    Hi, All

    I need to parse ISO8601-formatted date got from API based on Django REST framework (Python language, if correct).
    Date sample "2018-09-03T17:20:15.841985+07:00" is parsed well (after removing "T") by
    Code:
    DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSSX"
    by B4A 8.3 and JDK v.1.8.0.x.

    But if to try to generate the same ISO8601 timestamp, according to the doc: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

    "XXX" should give the required time zone "-08:00", but
    Code:
    DateTime.TimeFormat = "HH:mm:ss.SSSSSSX" 'gives...
    java.lang.IllegalArgumentException: Unknown pattern character 'X'
    Unclear why if "X" is OK for parsing.
    Any suggestions ? (i see that manually add ":" into th result it's OK, but ... )
     
    Last edited: Sep 6, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. peacemaker

    peacemaker Well-Known Member Licensed User

    Yes, Erel, no other topics for ISO8601 on the forum. Here other variants of the format.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    See that post. You will understand how to add the T character to the format.

    Post the date string that doesn't work with this format:
    "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
     
  5. peacemaker

    peacemaker Well-Known Member Licensed User

    Code:
    DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSX"  'gives 2018-09-10T07:32:04.730000Z

    DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ss.mmmmmmZ"   'gives 2018-09-10T07:33:03.199035+0000, but it's not +00:00
    Target is "2018-09-03T17:20:15.841985+07:00"
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Make it easier for us to help you. Post the 3 lines of code that show the problem.
     
  7. peacemaker

    peacemaker Well-Known Member Licensed User

    But what ?
    The same sub as in those thread, i just try to manipulate by the format to get target ISO8601 format: with microseconds (seems, it's impossible, only milliseconds with trailing "000" can be) and time zone like "+07:00", "-07:00".
    Code:
    Sub GetISO8601(dt As Long) As String
        
    Dim res As String ' dim string for the result
        Dim rememberdtformat As String = DateTime.DateFormat
        
    DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ" 
        res = 
    DateTime.Date(dt)
        
    DateTime.DateFormat = rememberdtformat
        
    Return res ' return the string build...
    End Sub
    And time zone cannot be got well.
     
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