This question was asked in 2010, and back then it was correct that either SimpleDateFormat
or Joda-Time would be the tools you should use. It’s quite a while ago now. Today use
Instant iStart = Instant.parse(dtStart);
Yes, it’s this simple. Your string is in ISO 8601 format, and the classes from java.time
, the modern Java date and time API, parse ISO 8601 without any explicit formatter. Instant
is just one of those classes.
Edit: Question: requires android API 26 - what about supporting older versions?
Yes, java.time
works nicely on older and newer Android devices. It just requires at least Java 6.
- In Java 8 and later and on newer Android devices (from API level 26) the modern API comes built-in.
- In Java 6 and 7 get the ThreeTen Backport, the backport of the new classes (ThreeTen for JSR 310; see the links at the bottom).
- On (older) Android use the Android edition of ThreeTen Backport. It’s called ThreeTenABP. And make sure you import the date and time classes from
org.threeten.bp
with subpackages.
Links