Today, I had to parse an ISO 8601 date that was returned as part of a JSON response from a REST service. With default settings GSON can’t parse the date like 2015-09-22T17:21:32.70856998Z. To make it work, use the code shown below.
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
.setPrettyPrinting()
.create();
Discover more from Shekhar Gulati
Subscribe to get the latest posts sent to your email.