Illegal Pattern Character 'T' When Parsing a Date String to java.util.Date
When attempting to parse a date string into a java.util.Date object using the SimpleDateFormat, developers may encounter the error "Illegal pattern character 'T'". This exception often arises due to mismatched formatting in the pattern used by SimpleDateFormat.
In most circumstances, the 'T' character should be included in the pattern if it exists in the input date string. It represents the transition between the date and time components and ensures proper parsing. In the provided example:
"yyyy-MM-ddThh:mm:ssZ"
The correct pattern should be:
"yyyy-MM-dd'T'hh:mm:ssZ"
where the 'T' character is enclosed in single quotes to escape it from being treated as the literal character 'T'.
Additionally, the pattern for the 'Z' suffix, representing Zulu or Coordinated Universal Time (UTC), is not simply 'Z', but rather 'XXX'. This is explained in the SimpleDateFormat documentation, though it can be confusing since 'Z' is also used for TimeZone information.
The above is the detailed content of Why Does Parsing a Date String with 'T' Throw an 'Illegal Pattern Character 'T'' Error in Java?. For more information, please follow other related articles on the PHP Chinese website!