通过从JavaScript中的特定日期减去X天数来查找日期 [英] Finding date by subtracting X number of days from a particular date in Javascript
本文介绍了通过从JavaScript中的特定日期减去X天数来查找日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过从JavaScript中的特定日期减去X天数来查找日期。我的JavaScript函数接受2个参数。一个是日期值,另一个是需要减去的天数。
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 and the other is the number of days that needs to be subtracted.
例如,我将我的参数日期作为2009年7月27日,我通过我的所以我想计算2009年7月27日前3天的日期。所以我们应该得到的结果日期是2009年7月24日。感谢任何帮助。
For example, I pass my argument date as 27 July 2009 and i pass my other argument as 3. So i want to calculate the date 3 days before 27 July 2009. So the resultant date that we should get is 24 July 2009. How is this possible in JavaScript. Thanks for any help.
推荐答案
简单地:
yourDate.setDate(yourDate.getDate() - daysToSubtract);
这篇关于通过从JavaScript中的特定日期减去X天数来查找日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文