我在jQuery中添加了几天,如下所示:
var today = new Date();
today.setHours(0,0,0,0);
alert(today.getDate()+23);
但它仅仅增加了几天,例如在上面的警报中我今天的日期(8月28日)得到43。
答案 0 :(得分:2)
var today = new Date();
today.setHours(0,0,0,0);
today.setDate(today.getDate()+23)
console.log(today)
答案 1 :(得分:2)
您需要先设置日期,然后再alert(today.getDate())
尝试如下:
var today = new Date();
today.setDate(today.getDate() + 23);
alert(today.getDate());
答案 2 :(得分:2)
使用:
var today = new Date();
var newdate = new Date();
newdate.setDate(today.getDate()+29);
alert(newdate);
答案 3 :(得分:0)
试试这个
<script type="text/jscript">
$(document).ready(function () {
var today = new Date();
today.setHours(0, 0, 0, 0);
today.setDate(today.getDate() + 30);
alert(today);
});