You can use moment to parse date strings.
By default moment tries to parse the date as an ISO-8601 string and if that does not work falls back to the browsers new Date()
. Since the way that browsers construct dates varies it is best to try not to fall back to this.
moment('2016-02-04').format('YYYY-MM-DD')
// ->'2016-02-04'
If you have a format other then ISO 8601 it is best to pass the format string as a second argument to moment.
moment('04-02-2016', 'MM-DD-YYYY').format('YYYY-MM-DD')
// ->'2016-02-04'