Assuming you have already installed the date-fns library in your project, you can use the startOfWeekYear
function as shown below:
index.ts180 chars6 lines
The startOfWeekYear
function takes two arguments:
The first argument is a Date object which represents the date for which you want to find the start of the ISO week-numbering year.
The second argument is an optional object with a weekStartsOn
property which specifies which day of the week the week starts on. The default value is 0, which corresponds to Sunday. If you want the week to start on Monday, you can pass {weekStartsOn: 1}
as the second argument.
The function returns a new Date object which represents the start of the ISO week-numbering year.
Note: The startOfWeekYear
function is available from version 2.17.0 of the date-fns library. If you are using an older version, you will need to upgrade the library to use this function.
gistlibby LogSnag