I am having following function
public static Date parseDate(String date, String format) throws ParseException
{
SimpleDateFormat formatter = new SimpleDateFormat(format);
return formatter.parse(date);
}
I am using this as follows in my code
Calendar eDate = Calendar.getInstance();
eDate.add(Calendar.DAY_OF_MONTH,10);
Date date = null;
try {
date = parseDate(eDate.getTime().toString(),"yyyy-MM-dd hh-mm-ss");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But it is throwing –
java.text.ParseException: Unparseable date
What is the problem here?
The format is not stored in the
Date. It is stored in theString. TheDate#toString()returns a fixed format which is described in its Javadoc.Do the formatting only at the moment you need to display a
Dateto a human as aString.Note that
MMstands for months andmmfor minutes. See alsoSimpleDateFormatjavadoc.