You can use the lastDayOfMonth
function from the date-fns
library in JavaScript to get the last day of a given month.
First, you need to install the date-fns
library using npm or yarn:
56 chars5 lines
Then, you can import the lastDayOfMonth
function and use it like this:
index.tsx220 chars7 lines
In the code above, we first import the lastDayOfMonth
function from the date-fns
library. Then, we create a new Date
object for February 11, 2022. Finally, we call the lastDayOfMonth
function with the date object, which returns the last day of the month (February 28, 2022 in this case).
gistlibby LogSnag