Add days to date using javascript

前端 未结 10 1303
执笔经年
执笔经年 2020-12-29 12:21

I am trying to add days to a given date using javascript. I have the following code

function onChange(e) {
    var datepicker = $(\"#DatePicker\").val();
           


        
10条回答
  •  猫巷女王i
    2020-12-29 12:43

    Date.prototype.addDays = function(days) {
        this.setDate(this.getDate() + days);
        return this;
    };
    

    and in your javascript code you could call

    var currentDate = new Date();
    // to add 8 days to current date
    currentDate.addDays(8);
    

提交回复
热议问题