To use the lastDayOfYear
function from date-fns
, you first need to install the package. You can do this using npm by running the following command:
index.tsx21 chars2 lines
Once you have the package installed, you can import the lastDayOfYear
function and use it in your code:
index.tsx176 chars7 lines
In the example above, we create a new Date
object representing January 1st, 2021. We then pass this object to the lastDayOfYear
function, which returns a new Date
object representing the last day of the year (December 31st, 2021 in this case). Finally, we log the result to the console.
Note that the lastDayOfYear
function returns a Date
object in UTC, so the output may differ depending on your timezone.
gistlibby LogSnag