js获取当前日期并格式yyy-MM-dd
//格式化日期:yyyy-MM-dd function formatDate(date) { var myyear = date.getFullYear(); var mymonth = date.getMonth() + 1; var myweekday = date.getDate(); if (mymonth < 10) { mymonth = "0" + mymonth; } if (myweekday < 10) { myweekday = "0" + myweekday; } return (myyear + "-" + mymonth + "-" + myweekday); } var date = new Date(); var dateStr=formatDate(date);
注意,之所以使用上面的格式,是因为我们有时候在前台使用input标签date类型传递的日期格式就是yyyy-MM-dd,我们要做到前后一致