Set the date to be the last day of last month: - Javascript Date

Javascript examples for Date:setMonth

Description

Set the date to be the last day of last month:

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  ww w.j  a va2s. c  om
    var d = new Date();
    d.setMonth(d.getMonth(), 0);
    document.getElementById("demo").innerHTML = d;
}
</script>

</body>
</html>

Related Tutorials