在JavaScript中减去日期 [英] subtracting dates in javascript

查看:69
本文介绍了在JavaScript中减去日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能看起来像这样

hi people i have a function looks like this

var months = new Array(12);
months[0] = "JANUARY";
months[1] = "FEBRUARY";
months[2] = "MARCH";
months[3] = "APRIL";
months[4] = "MAY";
months[5] = "JUNE";
months[6] = "JULY";
months[7] = "AUGUST";
months[8] = "SEPTEMBER";
months[9] = "OCTOBER";
months[10] = "NOVEMBER";
months[11] = "DECEMBER";

var current_date=new Date();
month_value = current_date.getMonth();




现在,我正在尝试获取此功能以使7个月的月份恢复原状

我该怎么做?




Now i am trying to get this function to get the month of 7 days back

How do i do that?

推荐答案

没有得到为什么要使用此方法的原因.
使用类似的内容:
Didn''t got why you want to use this method.

Use something like:
var todaysDate = new Date();todaysDate.setDate(todaysDate.getDate()-7);


使用日期属性,可以获得新日期的天/月/年.


Using date properties, you can get day/month/year of the new date.


这篇关于在JavaScript中减去日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆