I have the following ISO8601-compliant string:
2024-03-25T11:34:15.000Z
I need to convert it to java Date. I found the following solution:
Date date = Date.from(Instant.parse("2024-03-25T11:34:15.000Z"));
long epoch = date.getTime());
However, this requires at least Android Oreo. I need a converter that works down to KitKat. Any idea?
Tried following solutions but had the same issue:
I also found a solution by using JAXB but I read somewhere that it bloats my APK by 9MB! With it, the solution could be this simple:
javax.xml.bind.DatatypeConverter.parseDateTime(iso8601Date).getTimeInMillis();
Instant.parse("2024-03-25T11:34:15.000Z").toEpochMilli()
? – Philologianjava.time
exists because those old classes are buggy. You might like to investigate whether Joda can do it for you – PhilologianDate
. In your example code it’s a needless detour. Use justInstant.parse("2024-03-25T11:34:15.000Z").toEpochMillis()
to get the milliseconds since the epoch. – Armagh