js 获取当前日期的前三个月

当前月份
var date=new Date;
var year=date.getFullYear();
var month=date.getMonth()+1;
month =(month<10 ? “0”+month:month);
eDate = (year.toString()+’-’+month.toString());

前3个月
var date1 = new Date();
date1.setMonth(date1.getMonth()-2);
var year1=date1.getFullYear();
var month1=date1.getMonth()+1;
month1 =(month1<10 ? “0”+month1:month1);
sDate = (year1.toString()+’-’+month1.toString());

你可能感兴趣的:(前段原生JS)