Understanding Date Format: 2011-08-12T20:17:46.384Z
Unable to parse the date string "2011-08-12T20:17:46.384Z" using DateFormat.getDateInstance().parse(dateStr), the question arises regarding the unrecognized format.
Decoding the Format
The given date format, "2011-08-12T20:17:46.384Z", consists of the following elements:
Creating a SimpleDateFormat
To successfully parse the date string, SimpleDateFormat can be used. Below is the code to create a SimpleDateFormat object that can handle the given format:
SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC"));
Using Joda Time
Alternatively, Joda Time provides a convenient way to parse the date string:
DateTimeFormat.dateTime().parseDateTime("2011-08-12T20:17:46.384Z");
The above is the detailed content of How to Parse the Date String '2011-08-12T20:17:46.384Z'?. For more information, please follow other related articles on the PHP Chinese website!