要获取某一天的周一日期,你可以使用JavaScript中的Date对象和一些日期计算方法。
function getMonday(date) {
const day = date.getDay();
const diff = date.getDate() - day + (day === 0 ? -6 : 1); // 调整星期天的情况
return new Date(date.setDate(diff));
}
const date = new Date(); // 获取当前日期
const monday = getMonday(date); // 获取当前日期所在周的周一日期
console.log(monday);
要获取某个月的月底时间
// 创建一个Date对象,表示当前时间:
var currentDate = new Date();
// 获取当前月份和年份:
var currentMonth = currentDate.getMonth();
var currentYear = currentDate.getFullYear();
// 创建一个新的Date对象,将月份设置为下个月的第一天:
var nextMonth = new Date(currentYear, currentMonth + 1, 1);
//将日期设置为上个月的最后一天:
nextMonth.setDate(nextMonth.getDate() - 1);