Skip to main content
@spa-tools/utilities

addMilliseconds()

The addMilliseconds() function adds a number of milliseconds to a given date object, timestamp integer, or date string.

Usage

import { addMilliseconds } from '@spa-tools/utilities';

const date = new Date('2021-01-01');
console.log(date.toISOString());
// --> '2021-01-01T00:00:00.000Z'

const newDate1 = addMilliseconds(date, 50);
console.log(newDate1.toISOString());
// --> '2021-01-01T00:00:00.050Z'

const newDate2 = addMilliseconds(date, 1000);
console.log(newDate2.toISOString());
// --> '2021-01-01T00:00:01.000Z'

const newDate3 = addMilliseconds(date, 10000);
console.log(newDate3.toISOString());
// --> '2021-01-01T00:00:10.000Z'

Arguments

NameTypeRequired?Description
datestring | number | DateyesThe date value to add milliseconds to as either date string, timestamp integer, or date object
millisecondsnumberyesThe number of milliseconds to add

Returns

Date - The new date object with the added milliseconds.