0

I have date in string format of (yyyy-MM-dd), i want to assign this with same format to Date object.

i tried with new SimpleDateFormat(yyy-MM-dd).parse(dateString) and further assigned it to Date, but format not carry.

new SimpleDateFormat(yyy-MM-dd).parse(dateString);

No error in parsing

Prashant Katara
  • 95
  • 1
  • 1
  • 14
  • 8
    Date objects do not include formatting information. Also, it's probably about time to start using the `java.time` classes instead of the legacy `java.util` stuff. – Robby Cornelissen Aug 23 '19 at 06:29
  • 1
    I recommend you don’t use `SimpleDateFormat` and `Date`. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use `LocalDate` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). BTW `LccalDate` does print in the format you asked for since it is what its `toString` method produces. – Ole V.V. Aug 23 '19 at 07:33

1 Answers1

0

Try this:

new SimpleDateFormat("yyyy-MM-dd").parse(dateString);

In your case three letter y but four needed

Elgin
  • 95
  • 5