Format JavaScript Date to yyyy-mm-dd
Temperature: 0 °C
JavaScript將Sun May 01,2018轉換成yyyy-mm-dd
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('-');
}
document.getElementById('res').innerHTML = formatDate('Sun May 01,2018') ;
以上紀錄~