JavaScript,获取第二天的日期

编程入门 行业动态 更新时间:2024-10-28 00:18:25
本文介绍了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,获取第二天的日期

本文发布于:2023-11-24 02:51:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第二天   日期   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!