I ma getting exeception while parsing the date.
following is the code:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD");
Date d = format.parse("2014/02/20");
System.out.println(d);
Not only have you got the slashes/dashes wrong, you're also using DD (day of year) instead of dd (day of month). You want:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
As always, read the documentation to find out exactly what pattern symbols mean - and if you find it's behaving oddly, check the pattern against the data very carefully.
I would also recommend:
java.time (Java 8) if you possibly can; the java.util.Date/Calendar API is horribleCurrently you're using the default time zone and locale. While the locale may not matter in this case (unless it's used to pick the calendar system; I can't remember offhand) I think it's clearer to explicitly specify it. The time zone definitely matters; if you only ever want to treat this as a date (no time) it's probably worth specifying UTC - that way it's easy to interoperate with anything else, and you get day boundaries in obvious places in the underlying millisecond representation.
Your dateformat doesn't match your string.
Date d = format.parse("2014-02-20");
or
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
DD is for day in a year (this is not me who downvoted)In modern Java, use LocalDate class to represent a date-only value, without time-of-day, and without time zone or offset-from-UTC.
Replace the / separators with - to comply with ISO 8601 standard format.
LocalDate ld = LocalDate.parse( "2014/02/20".replace( "/" , "-" ) ) ;
Or define a formatter.
DateTimeFormatter f = DateTimeFormatter.ofPattern( "uuuu/MM/dd" ) ;
LocalDate ld = LocalDate.parse( "2014/02/20" , f ) ;
DDwithdd.Check