javascript函数连续一年从当前日期中减去日期 [英] javascript function to subtract date from current date consecutively for a year
问题描述
我想通过从JavaScript中减去特定日期的X天数来查找日期。我的JavaScript函数接受2个参数。一个是日期值(yyyy-mm-dd),另一个是需要减去的天数。
我连续减去30天一年。
例如:2014/12/30
2014/11/30
2014/10/30
2014/09/30
.....
。
。
。
。
。
2014/01/30
我试过这样的:
函数statement_cycle(日期,天数)
{
返回新日期(
date.getFullYear(),
date.getMonth(),
date.getDate() - 天,
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date .getMilliseconds()
);
}
i计算了一个月。我需要计算剩余的11个月
试试这个。 0作为日参数将返回上个月的日。
for ( month = 1 ; month< = 12 ; month ++){
var lastDay = new 日期(date.getFullYear(),month , 0 );
// 与您的最后一天做点什么
}
I want to find date by subtracting X number of days from a particular date in JavaScript. My JavaScript function accepts 2 parameters. One is the date value (yyyy-mm- dd) and the other is the number of days that needs to be subtracted.
I have subtract 30days consecutively for a year.
eg: 2014/12/30
2014/11/30
2014/10/30
2014/09/30
.....
.
.
.
.
.
2014/01/30
I have tried like this :
function statement_cycle(date,days)
{
return new Date(
date.getFullYear(),
date.getMonth(),
date.getDate() – days,
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date .getMilliseconds()
);
}
i have calculated for the one month. i need to calculate for the remaining 11 months
Try this. 0 as day parameter will return last month day.
for (month=1; month <= 12; month++) { var lastDay = new Date(date.getFullYear(), month, 0); // do something with your last day }
这篇关于javascript函数连续一年从当前日期中减去日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!