TL; DR
Skip formatting template. The standard ISO 8601 format is used by default.
Instant.parse( "2015-06-27T13:16:37.363Z" )
ISO 8601
The format of your string is formally defined by the ISO 8601 standard .
Basically your question is a duplicate of this, Converting a string compatible with ISO 8601 to java.util.Date .
Alternatives
Eugenioy's answer is correct.
But you should know that the old java.util.Date/.Calendar/java.text.SimpleDateFormat classes bundled with Java are notorious and should be avoided.
Deprecated Classes
Those old classes are now deprecated, first the third - party Joda-Time library, and now the new java.time package ( Tutorial ), built into Java 8 and later (inspired by Joda-Time, defined by JSR 310 , extended by ThreeTen-Extra ).
Both java.time and Joda-Time use the ISO 8601 standard as default values when parsing / generating string representations of date and time values. Thus, the code is simple; there is no need for custom formatting objects. No need to use all of this format that caused your exception.
Timezone
Both java.time and Joda-Time have a zoned time class that understands its assigned time zone (unlike java.util.Date). If you did not assign it, the current JVMs default time zone is assigned.
Beware that the current time zone of JVMs can change at any time. It can change during deployment, by default it does not depend on host settings. And it can change at any time during execution, when any code in any thread of any application in the JVM calls TimeZone.setDefault . Therefore, it is better to explicitly assign the desired / expected time zone.
java.time
Z at the end of the line is short for Zulu and means UTC. The Instant class can directly analyze this format to represent the moment on the timeline in UTC with a resolution in nanoseconds.
String input = "2015-06-27T13:16:37.363Z"; Instant instant = Instant.parse( input );
Change the time zone from UTC to any desired / expected time zone.
ZoneID zone = ZoneId.of( "America/Montreal" ) ; ZonedDateTime zdtMontréal = instant.atZone( zone ) ;
If you really need java.util.Date to interact, convert.
java.util.Date utilDate = Date.from( zdtMontréal.toInstant() ) ;
Joda time
The Joda-Time project is now in maintenance mode, and the team advises switching to the java.time classes.
Sample code using Joda-Time 2.8.1.
String input = "2015-06-27T13:16:37.363Z" ; DateTimeZone zone = DateTimeZone.UTC ; // Or: DateTimeZone.forID( "America/Montreal" ) ; DateTime dateTime = new DateTime( input, zone ) ;
If you really need java.util.Date to interact, convert.
java.util.Date date = dateTime.toDate();