Date.setTime()
Sets a date to a specified number of milliseconds after/before January 1, 1970
The setTime() method sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC.
var event1 = new Date('July 1, 1999');
var event2 = new Date();
event2.setTime(event1.getTime());
console.log(event1);
// expected output: Thu Jul 01 1999 00:00:00 GMT+0200 (CEST)
console.log(event2);
// expected output: Thu Jul 01 1999 00:00:00 GMT+0200 (CEST)
// (note: your timezone may vary)
Syntax
dateObj.setTime(timeValue)
Parameters
timeValue
An integer representing the number of milliseconds since 1 January 1970, 00:00:00 UTC.
Return value
The number of milliseconds between 1 January 1970 00:00:00 UTC and the updated date (effectively, the value of the argument).
Description
Use the setTime()
method to help assign a date and time to another Date
object.
Examples
Using setTime()
setTime()
var theBigDay = new Date('July 1, 1999');
var sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());
References
Contributors to this page
Uros Durdevic
Last updated