Android Question ISO8601 time zone

peacemaker

Expert
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
B4X:
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
B4X:
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:

peacemaker

Expert
Licensed User
B4X:
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"
 
Upvote 0

peacemaker

Expert
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".
B4X:
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.
 
Upvote 0
Top