To use the previousthursday
function from date-fns
library in JavaScript, you first need to install the library using npm.
21 chars2 lines
After installing, you can import the previousthursday
function in your JavaScript file using the following code:
index.tsx50 chars2 lines
You can then call the previousthursday
function, passing a Date or a string representing a valid date, to get the date of the previous Thursday.
index.tsx100 chars2 lines
You can also pass a second optional parameter to the previousthursday
function, which is an object containing options for the function.
index.tsx180 chars2 lines
In the example above, the weekStartsOn
option is passed to previousthursday
function with a value of 1, which indicates that Monday is considered as the first day of the week.
gistlibby LogSnag