本文介绍了Javascript下一个和前一天的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发日历,需要遍历下一天和前一天。我怎么用javascript写这个?进入下一个/上个月时,以下是否会正确计算?喜欢C#的DateTime.Today.AddDays(1)会吗?
I am developing a daily calendar and need to traverse to the next and previous day. How would I write this in javascript? Will the following calculate correctly when going to the next / previous month? Like C#'s DateTime.Today.AddDays(1) will?
new Date(year, month, day + 1)我担心的是,如果我在3月31日执行此操作,它将计算3月32日...这不会很明显。
My concern is that if I execute this on March 31st, it will calculate March 32nd...which wouldn't work obviously.
如果有人可以提供这样做的功能,那就太棒了!
If someone could provide a function to do both that would be great!
提前致谢!
推荐答案var dateString = '30 Apr 2010'; // date string var actualDate = new Date(dateString); // convert to actual date var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate()+1); // create new increased date
更多推荐
Javascript下一个和前一天的功能
发布评论