Sow nothing reap nothing

JS获取当月第一天和下个月第一天

已有2,478次关注

输出效果:
JS获取当月第一天和下个月第一天.png

首先创建时间对象:

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";

已自动关闭评论