Java – simpledateformat cannot resolve date
•
Java
I have encountered some problems parsing string so far I searched for an idea on stackoverflow, and I got my answer, but it still doesn't work So
I try to parse a string that looks like this
What I'm trying is this
private Date getDateFromString(String sDate) { String dateFormat = "EEE MMM dd HH:mm:ss z yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); sdf.setTimeZone(TimeZone.getTimeZone("CET")); Date newDate = null; try { newDate = sdf.parse(sDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return newDate; }
Of course someone can help me: -) thank you for your prediction
Solution
The problem is the interpretation of "Tue" and "Jan" because you did not specify any locale (in this case, it uses the default locale (locale. Getdefault())
Try:
new SimpleDateFormat(dateFormat,new Locale("en_US"));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码