1

We are using a back-end server built with ASP.NET Core 2.1, which is returning DateTime using ISO 8601 to the clients Web / Android / iOS.

The problem is that the back-end is formatting date and time using a variable fraction of seconds, which both Android and iOS does not expect from their fixed yyyy-MM-ddThh:mm:ss.SSSZ format.

Now, we know that from iOS 11 there is a proper ISO 8601 deserializer, but we cannot move from iOS 9; for Android we did not found a solution yet.

We are struggled if we need to implement a custom DateTime formatter on back-end and deliver a fixed datetime format and potentially break the standard (we would like to serialize DateTimeOffset too for timezones management) or find a solution on client side.

W3C clearly says that a variable fraction of seconds needs to be supported to being ISO 8601 compatible: https://www.w3.org/TR/NOTE-datetime

What would be the best future-proof solution?

user3040937
  • 81
  • 10
  • Are you using Java on Android? `java.time`, the modern Java date and time API can do that stuff out of the box. It’s built in from API level 26 and also backported to earlier API levels. I’d call that a future-proof solution. – Ole V.V. Jul 26 '18 at 18:24

1 Answers1

2

Try something like this

val format = SimpleDateFormat("yyyy-MM-ddThh:mm:ss.SSSZ")
textView.text = format.format(date)
  • 1
    This is not working with the following ISO 8601 formats: 1997-07-16T19:20Z 1997-07-16T19:20:59Z 1997-07-16T19:20+01:00 – user3040937 Jul 26 '18 at 16:08
  • year, it`s realy not easy problem)). May be you can find solution here https://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date – logoped583st Jul 26 '18 at 17:21
  • The Java `SimpleDateFormat` class is long outdated and notoriously troublesome. – Ole V.V. Jul 26 '18 at 18:26