Time Processing and Retrieval

javascript; time; date
82 words

Getting All Dates of the Current Week

Here's a common question: "Should Monday or Sunday be the start of the week?"

dayjs

dayjs doesn't have a dedicated method to set this, but you can achieve it indirectly by configuring the internationalization language settings

import dayjs from 'dayjs';
import localeData from 'dayjs/plugin/localeData';
dayjs.extend(localeData);

// Set the start of the week to Monday
dayjs.locale('zh-cn'); // Monday is the default start of the week in Chinese locale

// Time range for the current week
const thisWeekRange = [dayjs().startOf('week'), dayjs().endOf('week')]