javascript convert string to date format yyyy-mm-dd code example
Example 1: javascript convert date to yyyy-mm-dd
const formatYmd = date => date.toISOString().slice(0, 10);
formatYmd(new Date());
Example 2: javascript format date yyyy-mm-dd
let today = new Date()
today.toISOString().split('T')[0]
Example 3: format date js
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today = new Date();
console.log(today.toLocaleDateString("en-US"));
console.log(today.toLocaleDateString("en-US", options));
date.toLocaleDateString("en-US", { day: 'numeric' })+ "-"+ date.toLocaleDateString("en-US", { month: 'short' })+ "-" + date.toLocaleDateString("en-US", { year: 'numeric' })
Example 4: javascript date parse yyyy-mm-dd
var dateString = "10/23/2015";
var dateObject = new Date(dateString);
document.body.innerHTML = dateObject.toString();