javascript日期添加天数出错天数
我在页面上使用此代码来显示接下来的几天是什么时候,它们总是接下来的几天。。。但它现在不起作用:javascript日期添加天数出错天数,javascript,date,Javascript,Date,我在页面上使用此代码来显示接下来的几天是什么时候,它们总是接下来的几天。。。但它现在不起作用: <script>var now = new Date(); var day = ("0" + (now.getDate()+3)).slice(-2); var day2 = ("0" + (now.getDate()+4)).slice(-2); var month = ("0" + (now.getMonth() + 1)).slice(-2); var
<script>var now = new Date();
var day = ("0" + (now.getDate()+3)).slice(-2);
var day2 = ("0" + (now.getDate()+4)).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var today = (month)+"/"+(day)+"/"+now.getFullYear();
var today2 = (month)+"/"+(day2)+"/"+now.getFullYear();
document.write(today); document.write(' and/or ');document.write(today2);
</script>
如果需要的话,我如何让+1进入下个月?试试这个
<script>
var now = new Date();
var day = ("0" + (now.setDate(now.getDate()+3)).getDate()).slice(-2);
var day2 = ("0" + (now.setDate(now.getDate()+4)).getDate()).slice(-2);
var month = ("0" + (now.setMonth(now.getMonth() + 1+1)).getMonth()).slice(-2);
var today = (month)+"/"+(day)+"/"+now.getFullYear();
var today2 = (month)+"/"+(day2)+"/"+now.getFullYear();
document.write(today); document.write(' and/or ');document.write(today2);
</script>
var now=新日期();
var day=(“0”+(now.setDate(now.getDate()+3)).getDate()).slice(-2);
var day2=(“0”+(now.setDate(now.getDate()+4)).getDate()).slice(-2);
var month=(“0”+(now.setMonth(now.getMonth()+1+1)).getMonth()).slice(-2);
var today=(月)+“/”+(日)+“/”+now.getFullYear();
var today2=(月)+“/”+(第2天)+“/”+now.getFullYear();
文件。写(今天);文件。书写(‘和/或’);文件编写(今天2);
只需为要提示的每个日期创建一个日期。您是在添加数字,而不是添加日期。请参阅,例如,了解想法。纯代码答案没有帮助,这是重复的。
<script>
var now = new Date();
var day = ("0" + (now.setDate(now.getDate()+3)).getDate()).slice(-2);
var day2 = ("0" + (now.setDate(now.getDate()+4)).getDate()).slice(-2);
var month = ("0" + (now.setMonth(now.getMonth() + 1+1)).getMonth()).slice(-2);
var today = (month)+"/"+(day)+"/"+now.getFullYear();
var today2 = (month)+"/"+(day2)+"/"+now.getFullYear();
document.write(today); document.write(' and/or ');document.write(today2);
</script>