How can I do this conversion in Java?
I am currently doing:
public static String formatDate(String strDateToFormat) {
try {
SimpleDateFormat sdfSource = new SimpleDateFormat("EEEE, MMMM DD, YYYY");
Date date = sdfSource.parse(strDateToFormat);
SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd");
return sdfDestination.format(date);
} catch (ParseException pe) {
System.err.println("Parse Exception : " + pe);
}
return null;
}
However, this leads to the wrong format. It gives me the following result:
Friday, February 1, 2013 > 2013-01-04
Thursday, January 31, 2013 > 2013-01-03
source
share