Date.prototype.setTime()

The setTime() method of Date instances changes the timestamp for this date, which is the number of milliseconds since the epoch, defined as the midnight at the beginning of January 1, 1970, UTC.

Try it

Syntax

js
setTime(timeValue)

Parameters

timeValue

An integer representing the new timestamp — the number of milliseconds since the midnight at the beginning of January 1, 1970, UTC.

Return value

Changes the Date object in place, and returns its new timestamp. If timeValue is NaN (or other values that get coerced to NaN, such as undefined), the date is set to Invalid Date and NaN is returned.

Examples

Using setTime()

js
const theBigDay = new Date("1999-07-01");
const sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());

Specifications

Specification
ECMAScript Language Specification
# sec-date.prototype.settime

Browser compatibility

BCD tables only load in the browser

See also