生成3个月前的时间日期

1

var currDate = new Date();
year = currDate.getFullYear();
month = currDate.getMonth() + 1;
date = currDate.getDate();
hour = currDate.getHours();
minute = currDate.getMinutes();
second = currDate.getSeconds();
 
switch (month) {
    case 1:
    case 2:
    case 3:
        month += 9;
        year--;
        break;
    default:
        month -= 3;
        break;
}
 
var datechar = year + "-" + (month > 9 ? month : "0" + month) + "-" +
    (date > 9 ? date : "0" + date) + " " +
    hour + ":" + minute + ":" + second;
//return datechar;
 
console.log(datechar);

1

posted @ 2022-03-30 22:04  MING5135  阅读(117)  评论(0)    收藏  举报