0

How can I convert date string to date object in javascript in yyyy-mm-dd format i.e 2021-06-10

let date = '2021-06-10' //typeof == string

or

let date = 2021-06-10T00:00:00.000Z  // I want only 2021-06-10 of type date and not string

the typeof must give me date type instead of string. I have tried toString(), toLocaleString() etc etc, all these gives me dates in string , but I have to set the value in form control so this must be of date type.

Any help!!

D.K
  • 80
  • 1
  • 12
  • [Something like this?](https://stackoverflow.com/a/24642753/8089674) – Robo Mop Jun 16 '21 at 12:37
  • possible duplicate question - https://stackoverflow.com/questions/17692863/converting-string-in-iso8601-t-z-format-to-date – Supesu Jun 16 '21 at 12:37
  • In Angular, you may still have date type object, and the display format for this can be defined using pipes in template [date transform pipes](https://angular.io/api/common/DatePipe#format-examples) – Wazeed Jun 16 '21 at 12:48

0 Answers0