peacemaker Expert Licensed User Longtime User Sep 6, 2018 #1 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: Copy 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: Copy 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
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: Copy 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: Copy 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 ... )
Erel B4X founder Staff member Licensed User Longtime User Sep 7, 2018 #2 Have you tried this: ISO 8601 date/time formatting Upvote 0
peacemaker Expert Licensed User Longtime User Sep 7, 2018 #3 Yes, Erel, no other topics for ISO8601 on the forum. Here other variants of the format. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Sep 9, 2018 #4 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" Upvote 0
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"
peacemaker Expert Licensed User Longtime User Sep 10, 2018 #5 Code: Copy 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
Code: Copy 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"
Erel B4X founder Staff member Licensed User Longtime User Sep 11, 2018 #6 Make it easier for us to help you. Post the 3 lines of code that show the problem. Upvote 0
peacemaker Expert Licensed User Longtime User Sep 11, 2018 #7 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: Copy 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
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: Copy 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.