Ruben Ruben - 5 months ago 16
Java Question

How to convert a tring to Date in Java?

I get a time string like "Thu, 11 Aug 2016 00:33:30 GMT".And I want to convert it to a Date object in Java.
I do it with the code:

String timeString= "Thu, 11 Aug 2016 00:33:30 GMT";
SimpleDateFormat inputFormat = new SimpleDateFormat
("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.CHINA);
Date date= null;
try {
date = inputFormat.parse(timeString);
} catch (ParseException e) {
// TODO Auto-generated catch block

But I got a "java.text.ParseException: Unparseable date: 'Thu, 11 Aug 2016 00:33:30 GMT'" exception.
Is everyone know why?Thanks a lot...


The problem is with Locale.CHINA. Aug is not in China language and changing it to Locale.ENGLISH will solve the problem.