我一直在尝试制作这样的东西const dateFormated=startDate.toLocaleDateString((.split("."(.join("-"(;
但它的顺序不正确,它丢失的数字反而是06它的6
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
console.log(formatDate('Sun May 11,2014'));