首页 > 代码库 > js日期操作

js日期操作

Javascript Data Type How to - Add days to current date








Question

We would like to know how to add days to current date.

Answer


<!--from   w  ww .  j a v a2s  . co  m-->
<!DOCTYPE html>
<html>
<head>
<script type=‘text/javascript‘>
window.onload=function(){
    var today = new Date();
    var newdate = new Date();
    newdate.setDate(today.getDate()+29);
    document.writeln(newdate);
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows:

js日期操作