Home >Java >javaTutorial >How to Resolve \'java.text.ParseException: Unparseable Date\' Exception?
Resolving "java.text.ParseException: Unparseable Date" Exception
When attempting to parse a date using SimpleDateFormat, an "Unparseable Date" exception may arise due to mismatched input string formats. To address this, the input string and SimpleDateFormat pattern must be aligned.
In this specific case, the input string "Sat Jun 01 12:53:10 IST 2013" does not correspond to the pattern "MMM d, yyyy HH:mm:ss" used by the SimpleDateFormat instance. To correctly parse the input, a different pattern is required.
The revised pattern below accommodates the specific elements in the input string:
SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
Additionally, to print the parsed date in the desired format, another SimpleDateFormat instance is required:
Date parsedDate = sdf.parse(date); SimpleDateFormat print = new SimpleDateFormat("MMM d, yyyy HH:mm:ss"); System.out.println(print.format(parsedDate));
Notes:
The above is the detailed content of How to Resolve \'java.text.ParseException: Unparseable Date\' Exception?. For more information, please follow other related articles on the PHP Chinese website!