SimpleDateFormat with "yyyy-MM-dd'T'HH:mm:ss'Z'" Does Not Automatically Set Timezone
The Java SimpleDateFormat constructor:
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
by itself does not set the timezone. Adding a 'Z' to the end of the date/time string merely indicates a GMT/UTC timezone, but does not actually change the underlying date/time value.
To ensure that the parsed date/time is in GMT/UTC, you must explicitly set the timezone.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); Date date = sdf.parse("2013-09-29T18:46:19Z");
By setting the timezone to GMT, the parsed date/time will be converted to GMT and displayed correctly.
The above is the detailed content of Does `SimpleDateFormat('yyyy-MM-dd'T'HH:mm:ss'Z'')` Automatically Handle Time Zones?. For more information, please follow other related articles on the PHP Chinese website!