Date setTime() Method - Javascript Date

Javascript examples for Date:setTime


The setTime() method sets a date by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970.



Parameter Values

Parameter Description
millisec Required. The number of milliseconds to be added to, or subtracted from, midnight January 1, 1970

Return Value:

A Number, representing the number of milliseconds between the date object and midnight January 1 1970

Add 99912345 milliseconds to January 1, 1970, and display the new date and time:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {//from   w ww  .  j av  a 2 s  . c om
    var d = new Date();
    document.getElementById("demo").innerHTML = d;


Related Tutorials