You can use the roundToNearestMinutes
function from the date-fns library in typescript as follows:
index.ts250 chars8 lines
In the above code, we import the roundToNearestMinutes
function from the date-fns library using the ES6 import syntax. Next, we create a new Date
object representing the current date and time. Finally, we call the roundToNearestMinutes
function with the date
object and an options object specifying the nearestTo
parameter as 15
to round the date to the nearest 15 minutes. The roundedDate
object returned by the function call represents the rounded date and time, which we log to the console.
Note that this function returns a new date object and does not modify the original date object passed as input argument.
gistlibby LogSnag