The setTime() method sets a date and time by adding/subtracting a specified number of milliseconds to/from midnight January 1, 1970.
The setTime() method sets a date and time by adding/subtracting a specified number of milliseconds to/from midnight January 1, 1970.
Date.setTime(millisec)
Parameter | Require | Description |
---|---|---|
millisec | Required. | The number of milliseconds to be added to, or subtracted from, midnight January 1, 1970 |
A Number, representing the number of milliseconds between the date object and midnight January 1 1970
Add 12345678 milliseconds to January 1, 1970, and display the new date and time:
//display the date after setting the time. var d = new Date(); d.setTime(12345678);/* w w w . j a v a 2 s.c om*/ console.log(d); //Subtract 12345678 milliseconds from January 1, 1970, and display the new date and time: var d = new Date(); d.setTime(-12345678); console.log(d);