Javascript下一个和前一天的功能

编程入门 行业动态 更新时间:2024-10-12 18:21:17
本文介绍了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下一个和前一天的功能

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

发布评论

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

>www.elefans.com

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