I have date in the format "yyyy-MM-dd'T'HH:mm:ss.sssZ". for example the date is "2018-07-17T09:59:51.312Z". I am using the below code to parse the String in Java.
String date="2018-07-17T09:59:51.312Z";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssZ");
Date transactionDateTime = simpleDateFormat.parse(date);
This is giving me "Unparseable date:" Exception. Can anyone please tell me how to do this?
解决方案
You forgot to add ' before the Z - RFC 822 time zone (-0800)
String date = "2018-07-17T09:59:51.312Z";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Date transactionDateTime = simpleDateFormat.parse(date);
That will do the work