I am working on a Spring project and I have to search Documents by date of upload. So when I pass my date as parameter of a method in DAO layer it's received like: Thu Jun 06 00:03:49 WEST 2013
. And I want to format that to : 2013-06-06
I have used this code to do that but it returns 06/06/13
and other constants of DateFormat (like DateFormat.MEDIUM, ...) do not return what I am waiting for.
DateFormat shortDf = DateFormat.getDateInstance(DateFormat.SHORT);
System.out.println(shortDf.format(new Date())); // return 06/06/13 it's short
I have also tried the SimpleDateFormat like that:
public static Date parseDate(String date, String format)throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat(format,Locale.ENGLISH);
return formatter.parse(date);
}
But it is still throwing a parsing Exception:
java.text.ParseException: Unparseable date: "Thu Jun 06 00:23:33 WEST 2013"
at java.text.DateFormat.parse(DateFormat.java:337)
at TestApp.main(TestApp.java:20)