Basically my date string is ISO-8601 date string, So I searched for converting ISO-8601 date string to date, but the solutions are lengthy. Here are the details.
I have a string 2018-02-02T06:54:57.744Z
want to convert it to Date but I am getting error:
java.text.ParseException: Unparseable date: "2018-02-02T06:54:57.744Z"
I am using following technique to do that but no success:
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
parser.setTimeZone(TimeZone.getTimeZone("UTC"));
Date parsed = parser.parse(utcDateString);
return parsed;
I also use following patterns with SimpleDateFormat
but no success:
yyyy-MM-dd'T'HH:mm:ss.SSSZ
yyyy-MM-dd HH:mm:ss.S
yyyy-MM-dd'T'HH:mm:ssX
yyyy-MM-dd'T'HH:mm'Z'
any solution to this problem.
SimpleDateFormat
and friends, and adding ThreeTenABP to your Android project in order to usejava.time
, the modern Java date and time API. It is so much nicer to work with.