JS简单的获取本地的年月日

var d = new Date;

var year = d.getFullYear();

var month = (d.getMonth() + 1) >=10? (d.getMonth() + 1) : "0" + (d.getMonth() + 1);

var date = d.getDate() >=10 ? d.getDate() : "0" + d.getDate();

var tempDate = year + "-" + month + "-" + date;

console.log(tempDate)  //输出格式:xxxx-xx-xx

你可能感兴趣的:(JS简单的获取本地的年月日)