Date setTime() Method - Javascript Date

Javascript examples for Date:setTime

Description

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

Syntax

date.setTime(millisec);

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>
<html>
<body>

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

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

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

</body>
</html>

Related Tutorials