JS中时间格式化方法
function resetQuery() { var dt = new Date(); var endTimeStr = formatDate(dt) ; $("#endTimeStr").val(endTimeStr); dt.setMonth( dt.getMonth()-2); var startTimeStr = formatDate(dt) ; $("#startTimeStr").val(startTimeStr); /* console.log( dt.toLocaleString() ); alert(dt.toLocaleString()); */ } 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); }