index.ts712 chars20 lines
In the function addTimeToDate
, we pass in a Date
object and the number of hours, minutes, seconds, and milliseconds we want to add to it. We make a copy of the original date using new Date(date)
and add each unit of time using the corresponding set
method of the Date
object. Finally, we return the new, modified Date
object. This function can be used in TypeScript or vanilla JavaScript.
gistlibby LogSnag