From e0e0a75519b018d5c498fbea4d1359cf2fe5cbb9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 2 Jul 2017 12:49:25 +0200 Subject: [PATCH] allow ISO format with miliseconds --- app/src/main/java/info/nightscout/utils/DateUtil.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index a4ee25eb22..b058450512 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -3,6 +3,7 @@ package info.nightscout.utils; import android.text.format.DateUtils; import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -24,6 +25,7 @@ public class DateUtil { * The date format in iso. */ public static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + public static String FORMAT_DATE_ISO_MSEC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; /** * Takes in an ISO date string of the following format: @@ -36,8 +38,15 @@ public class DateUtil { public static Date fromISODateString(String isoDateString) throws Exception { SimpleDateFormat f = new SimpleDateFormat(FORMAT_DATE_ISO); + Date date; f.setTimeZone(TimeZone.getTimeZone("UTC")); - Date date = f.parse(isoDateString); + try { + date = f.parse(isoDateString); + } catch (ParseException e) { + f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC); + f.setTimeZone(TimeZone.getTimeZone("UTC")); + date = f.parse(isoDateString); + } return date; }