@spa-tools/utilities
addMinutes()
The addMinutes()
function adds a number of minutes to a given date object,
timestamp integer, or date string.
Usage
import { addMinutes } from '@spa-tools/utilities';
const date = new Date('2021-01-01');
console.log(date.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '01/01/2021 12:00 AM'
const newDate1 = addMinutes(date, 5);
console.log(newDate1.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '01/01/2021 12:05 AM'
const newDate2 = addMinutes(date, 60);
console.log(newDate2.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '01/01/2021 1:00 AM'
const newDate3 = addMinutes(date, -60);
console.log(newDate3.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '12/31/2020 11:00 PM'
Arguments
Name | Type | Required? | Description |
---|---|---|---|
date | string | number | Date | yes | The date value to add minutes to as either date string, timestamp integer, or date object |
minutes | number | yes | The number of minutes to add |
Returns
Date
- The new date object with the added minutes.