Finding date by subtracting X number of days from a particular date in Javascript

后端 未结 9 1957
滥情空心
滥情空心 2020-11-27 05:21

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 i

9条回答
  •  时光取名叫无心
    2020-11-27 06:07

    function date_by_subtracting_days(date, days) {
        return new Date(
            date.getFullYear(), 
            date.getMonth(), 
            date.getDate() - days,
            date.getHours(),
            date.getMinutes(),
            date.getSeconds(),
            date.getMilliseconds()
        );
    }
    

提交回复
热议问题