To format a JavaScript date into “yyyy-mm-dd” format, use the toISOString() method. It converts using ISO standard i.e.
YYYY-MM-DDTHH:mm:ss.sss
Example
You can try to run the following code to format a date.
<html> <head> <title>JavaScript Dates</title> </head> <body> <script> var date, res; date = new Date(); res = date.toISOString(); document.write(res); </script> </body> </html>
Output
2018-12-15T08:13:47.648Z