Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.text.Parse Exception : Unparseable Date

I have the following code:

  String ModifiedDate = "1993-06-08T18:27:02.000Z" ;  
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  Date ModDate = sdf.parse(ModifiedDate);

I am getting the following exception even though my date format is fine...

java.text.ParseException: Unparseable date: "1993-06-08T18:27:02.000Z"
at java.text.DateFormat.parse(DateFormat.java:337)
like image 567
user2133404 Avatar asked Jun 12 '14 19:06

user2133404


1 Answers

The Z pattern latter indicates an RFC 822 time zone. Your string

String ModifiedDate = "1993-06-08T18:27:02.000Z" ;  

does not contain such a time zone. It contains a Z literally.

You'll want a date pattern, that similarly to the literal T, has a literal Z.

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

If you meant for Z to indicate Zulu time, add that as a timezone when constructing the SimpleDateFormat

sdf.setTimeZone(TimeZone.getTimeZone("Zulu"));;
like image 167
Sotirios Delimanolis Avatar answered Oct 17 '22 08:10

Sotirios Delimanolis