Add days to date using javascript

前端 未结 10 1154
执笔经年
执笔经年 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条回答
  •  隐瞒了意图╮
    2020-12-29 12:30

    Is it a typo round joindate.setDate(joindate + numberOfDaysToAdd)?

    I tried this code, it seems ok to me

        var joindate = new Date(2010, 5, 24);
        alert(joindate);
        var numberOfDaysToAdd = 1;
        joindate.setDate(joindate.getDate() + numberOfDaysToAdd);
        var dd = joindate.getDate();
        var mm = joindate.getMonth() + 1;
        var y = joindate.getFullYear();
        var joinFormattedDate = dd + '/' + mm + '/' + y;
        alert(joinFormattedDate);
    

提交回复
热议问题