<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.10.6/dayjs.min.js"></script>
</head>
<body>
<script>
const weekStart = 1;
function getLastWeek() {
const startOfWeek = dayjs().subtract(1, 'week').day(weekStart).format('YYYY-MM-DD') + ' 00:00:00';
const endOfWeek = dayjs().subtract(1, 'week').day(weekStart + 6).format('YYYY-MM-DD') + ' 23:59:59';
return { startOfWeek, endOfWeek };
}
function getCurrentWeek() {
const startOfWeek = dayjs().day(weekStart).format('YYYY-MM-DD') + ' 00:00:00';
const endOfWeek = dayjs().day(weekStart + 6).format('YYYY-MM-DD') + ' 23:59:59';
return { startOfWeek, endOfWeek };
}
function getNextWeek() {
const startOfWeek = dayjs().add(1, 'week').day(weekStart).format('YYYY-MM-DD') + ' 00:00:00';
const endOfWeek = dayjs().add(1, 'week').day(weekStart + 6).format('YYYY-MM-DD') + ' 23:59:59';
return { startOfWeek, endOfWeek };
}
function getLastMonth() {
const startOfMonth = dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD') + ' 00:00:00';
const endOfMonth = dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD') + ' 23:59:59';
return { startOfMonth, endOfMonth };
}
function getCurrentMonth() {
const startOfMonth = dayjs().startOf('month').format('YYYY-MM-DD') + ' 00:00:00';
const endOfMonth = dayjs().endOf('month').format('YYYY-MM-DD') + ' 23:59:59';
return { startOfMonth, endOfMonth };
}
function getNextMonth() {
const startOfMonth = dayjs().add(1, 'month').startOf('month').format('YYYY-MM-DD') + ' 00:00:00';
const endOfMonth = dayjs().add(1, 'month').endOf('month').format('YYYY-MM-DD') + ' 23:59:59';
return { startOfMonth, endOfMonth };
}
function getCurrentYear() {
const startOfYear = dayjs().startOf('year').format('YYYY-MM-DD') + ' 00:00:00';
const endOfYear = dayjs().endOf('year').format('YYYY-MM-DD') + ' 23:59:59';
return { startOfYear, endOfYear };
}
console.log(getLastWeek());
console.log(getCurrentWeek());
console.log(getNextWeek());
console.log(getLastMonth());
console.log(getCurrentMonth());
console.log(getNextMonth());
console.log(getCurrentYear());
</script>
</body>
</html>