I want to convert the date string "Fri Sep 21 15:23:59 CEST 2012" to "2012-09-21T15:23:59" in Java.
I tried this with SimpleDateFormat and the following code:
try {
String dateString = "Fri Sep 21 15:23:59 CEST 2012";
SimpleDateFormat input = new SimpleDateFormat("EEE MM dd HH:mm:ss z YYYY");
SimpleDateFormat output = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = input.parse(dateString);
System.out.println(output.format(date));
} catch (ParseException e) {
e.printStackTrace();
}
But the input parsing gives me a java.text.ParseException. I have read the documetation at http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html, but I am not able to find the error.
Which format string solves the input parsing of this string?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…