getDayOfYear
is a function provided by date-fns library which returns the day of the year of the given date.
Here's how you can use it in JavaScript:
21 chars2 lines
18 chars2 lines
getDayOfYear
function in your JavaScript file:index.tsx41 chars2 lines
getDayOfYear
function with a Date object:index.tsx117 chars4 lines
The above code will return the day of the year (74th day of the year) for the given date, which is March 15, 2022.
Note that the getDayOfYear
function returns the day of the year as a number between 1 and 366 (for leap years).
gistlibby LogSnag