javascript 使用javascript从当前日期起30天后的日期是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4191631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the date after 30days from current date using javascript
提问by Jeny
How can I find the date 30 days after the current day? here 30 is the fixed value. how can i pass the dynamic value to this function..
如何找到当前日期后 30 天的日期?这里 30 是固定值。我怎样才能将动态值传递给这个函数..
days = document.getElementById('day').value;
var d = new Date();
d.setDate(d.getDate() + days);
it is not working..it gives wrong answer
它不起作用..它给出了错误的答案
回答by David Conde
You can access the time in Javascript using the Date class. Try this:
您可以使用 Date 类在 Javascript 中访问时间。试试这个:
var time = new Date();
time.setDate(time.getDate()+30);
alert(time);
EDITJust added a test jsFiddle herein case somebody wants to test it.
编辑刚刚在这里添加了一个测试 jsFiddle以防有人想测试它。
Sorry I forgot the adding!!!
抱歉忘记加了!!!
回答by Anurag Uniyal
回答by David K.
var thirty_days_from_now = new Date((new Date()).getTime() + 30*24*60*60*1000)
回答by Pier Luigi
var d = new Date();
d.setDate(d.getDate() + 30);

