赞
踩
// 获取当前日期的上一个月 export function getlastMonth() { let now = new Date(); // 当前月的日期 let nowDate = now.getDate(); let lastMonth = new Date(now.getTime()); // 设置上一个月(这里不需要减1) lastMonth.setMonth(lastMonth.getMonth()); // 设置为0,默认为当前月的最后一天 lastMonth.setDate(0); // 上一个月的天数 let daysOflastMonth = lastMonth.getDate(); // 设置上一个月的日期,如果当前月的日期大于上个月的总天数,则为最后一天 lastMonth.setDate(nowDate > daysOflastMonth ? daysOflastMonth : nowDate); return lastMonth; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。