Set the time to 48 hours ago: - Javascript Date

Javascript examples for Date:setHours

Description

Set the time to 48 hours ago:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {/*  w w  w . j  a v a  2  s  .  com*/
    var d = new Date();
    d.setHours(d.getHours() - 48);
    document.getElementById("demo").innerHTML = d;
}
</script>

</body>
</html>

Related Tutorials