roundToNearestMinutes
import { roundToNearestMinutes } from "https://esm.sh/v135/date-fns@3.6.0/index.d.mts";
@example
// Round 10 July 2014 12:12:34 to nearest minute:
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34))
//=> Thu Jul 10 2014 12:13:00
@example
// Round 10 July 2014 12:12:34 to nearest quarter hour:
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { nearestTo: 15 })
//=> Thu Jul 10 2014 12:15:00
@example
// Floor (rounds down) 10 July 2014 12:12:34 to nearest minute:
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { roundingMethod: 'floor' })
//=> Thu Jul 10 2014 12:12:00
@example
// Ceil (rounds up) 10 July 2014 12:12:34 to nearest half hour:
const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { roundingMethod: 'ceil', nearestTo: 30 })
//=> Thu Jul 10 2014 12:30:00
function roundToNearestMinutes<DateType extends Date>(date: DateType | number | string, options?: RoundToNearestMinutesOptions): DateType;
§
roundToNearestMinutes<DateType extends Date>(date: DateType | number | string, options?: RoundToNearestMinutesOptions): DateType
[src]§Parameters
§
options?: RoundToNearestMinutesOptions optional
[src]- An object with options.