本文介绍了JavaScript,获取第二天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下脚本会在第二天返回:
I have the following script which returns the next day:
function today(i) { var today = new Date(); var dd = today.getDate()+1; var mm = today.getMonth()+1; var yyyy = today.getFullYear(); today = dd+'/'+mm+'/'+yyyy; return today; }通过使用以下命令:
today.getDate()+1;我要获取本月的第二天(例如今天要获取16)。
I am getting the next day of the month (for example today would get 16).
我的问题是,这可能是在该月的最后一天,因此最终返回了 32/4/2014
My problem is that this could be on the last day of the month, and therefore end up returning 32/4/2014
有没有办法保证第二天的正确日期?
Is there a way I can get the guaranteed correct date for the next day?
推荐答案您可以使用:
var tomorrow = new Date(); tomorrow.setDate(new Date().getDate()+1);例如,由于4月有30天,因此以下代码将输出5月1日:
For example, since there are 30 days in April, the following code will output May 1:
var day = new Date('Apr 30, 2000'); console.log(day); // Apr 30 2000 var nextDay = new Date(day); nextDay.setDate(day.getDate() + 1); console.log(nextDay); // May 01 2000请参见小提琴。
更多推荐
JavaScript,获取第二天的日期
发布评论