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

Javascript examples for Date:setDate

Description

Set the day of the month to be the last day of the previous 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() {//ww  w .j  a va 2s .  co m
    var d = new Date();
    d.setDate(0);
    document.getElementById("demo").innerHTML = d;
}
</script>

</body>
</html>

Related Tutorials