我从今天开始计算日期前 12 天。但它不会返回正确的日期。例如,对于今天 dat,11/11/2013 in (mm/dd/yyyy),它返回 10/30/2013,而它应该返回 10/31/2013。
这是代码
var d = new Date();
d.setDate(d.getDate() - 12);
d.setMonth(d.getMonth() + 1 - 0);
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
if (curr_month < 10 && curr_date < 10) {
var parsedDate = "0" + curr_month + "/" + "0" + curr_date + "/" + curr_year;
alert(parsedDate);
} else if (curr_month < 10 && curr_date > 9) {
var parsedDate = "0" + curr_month + "/" + curr_date + "/" + curr_year;
alert(parsedDate);
} else if (curr_month > 9 && curr_date < 10) {
var parsedDate = curr_month + "/" + "0" + curr_date + "/" + curr_year;
alert(parsedDate);
} else {
var parsedDate = curr_month + "/" + curr_date + "/" + curr_year;
alert(parsedDate);
}