输出效果:
首先创建时间对象:
var nowDate = new Date();
第二步使用三元运算符计算时间:
var nowMonth = nowDate.getFullYear() + "-" + (parseInt(nowDate.getMonth() + 1) < 10 ? "0" + parseInt(nowDate.getMonth() + 1):parseInt(nowDate.getMonth() + 1)) + "-01";
var afterMonth = nowDate.getFullYear() + "-" + (parseInt(nowDate.getMonth() + 2) < 10? "0" + parseInt(nowDate.getMonth() + 2):parseInt(nowDate.getMonth() + 2)) + "-01";