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.
date.setTime(millisec);
Parameter | 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 99912345 milliseconds to January 1, 1970, and display the new date and time:
<!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>