如何在当前日期之前30天获得?

编程入门 行业动态 更新时间:2024-10-10 20:17:23
本文介绍了如何在当前日期之前30天获得?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个开始日历输入框和一个结束日历输入框.我们希望将当前日期之前30天的默认开始日历输入框和当前日期作为结束日历输入框的默认值.这是我的约会变量.

I have a start calendar input box and an end calendar input box. We want defaults start calendar input box 30 days prior to current date and the end calendar input box to be the current date. Here is my date vars.

var today = new Date(), dd = today.getDate(), mm = today.getMonth(), yyyy = today.getFullYear(), month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October" "November", "December"], startdate = month[mm] + ", " + yyyy.toString();

结束日期类似于var enddate = startdate - 30;,显然这是行不通的.

The end date would be something like var enddate = startdate - 30; Obviously this won't work.

因此,如果当前日期为2011年12月30日,我希望开始日期为2011年12月1日.

So if the current date is December 30, 2011 I'd want the start date to read December 1, 2011.

我的问题得到了回答……有点. Date.today();和Date.today().add(-30);工作,但是我需要January 13, 2012格式的日期.不是Fri Jan 13 2012 10:48:56 GMT -055 (EST).有帮助吗?

My question was answered... sort of. Date.today(); and Date.today().add(-30); work but I need the date in the format of January 13, 2012. Not Fri Jan 13 2012 10:48:56 GMT -055 (EST). Any help?

更多撰写本文时为2018年.只需使用 Moment.js .最好.

MORE As of this writing it's 2018. Just use Moment.js. It's the best.

推荐答案

尝试使用出色的 Datejs JavaScript日期库(不再保留原始文档,因此您可能会对此主动维护的fork 感兴趣):

Try using the excellent Datejs JavaScript date library (the original is no longer maintained so you may be interested in this actively maintained fork instead):

Date.today().add(-30).days(); // or... Date.today().add({days:-30});

另请参见出色的 Moment.js JavaScript日期库:

moment().subtract(30, 'days'); // or... moment().add(-30, 'days');

更多推荐

如何在当前日期之前30天获得?

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

发布评论

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

>www.elefans.com

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