The addHours
function from date-fns is used to add a certain number of hours to an existing Date object.
To use the addHours
function, we need to:
Install date-fns via npm or yarn:
index.tsx21 chars2 lines
or
index.tsx18 chars2 lines
Import the addHours
function:
index.tsx37 chars2 lines
or
index.tsx42 chars2 lines
Call the addHours
function with the date object and the number of hours to add:
index.tsx113 chars5 lines
In the above code block, we create a new Date object and store it in the date
variable. We also specify the number of hours to add to this date using the hoursToAdd
variable. We then pass both variables to the addHours
function which returns a new Date object with the specified hours added to it. Finally we log the new date object to the console.
gistlibby LogSnag