Javascript Data Type How to - Add one day to a date








Question

We would like to know how to add one day to a date.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--   w w w.  j a  v  a 2  s  . c  om-->
var year = 2014;
var month = 3;
var day = 31;

requestedDate = new Date(year, month - 1, day);
document.writeln(requestedDate.toString());
document.writeln('<br/>');

var d = new Date(year, month - 1, day);
d.setDate(requestedDate.getDate()+1);
document.writeln(d.toString());

}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: