Javascript Data Type How to - Add one day to date








Question

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

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--  w  w w.j  a  v a 2s.c  om-->
    var dateString = 'Mon Jun 30 2014 00:00:00';
    var startDate = new Date(dateString);
    // seconds * minutes * hours * milliseconds = 1 day 
    var day = 60 * 60 * 24 * 1000;
    var endDate = new Date(startDate.getTime() + day);
    document.writeln(endDate);
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: