tl;dr
LocalDate.parse( "2017-04-14" )
Using java.time
You are using the wrong classes.
Avoid the troublesome old legacy classes such as Date
, Calendar
, and SimpleDateFormat
. Now supplanted by the java.time classes.
LocalDate
The LocalDate
class represents a date-only value without time-of-day and without time zone.
ISO 8601
Your input happens to comply with the ISO 8601 standard. The java.time classes use those standard formats by default when parsing/generating strings. So no need to specify a formatting pattern.
LocalDate ld = LocalDate.parse( "2017-04-14" );
To generate a string in the same format, call toString
.
String output = ld.toString() ;
Do not conflate strings with date-time objects. Date-time objects can be created by parsing a string. Date-time objects can generate strings to represent their value. But the string and the date-time are always separate and distinct.
Your first line in the Question uses a different format. I hope that was a mistake. You should stick with the ISO 8601 formats whenever possible, especially when serializing for data exchange.
If you really want other formats, search for DateTimeFormatter
. Already covered many many times on Stack Overflow.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.