Add days to date using javascript

前端 未结 10 1275
执笔经年
执笔经年 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:41

    I would like to encourage you to use DateJS library. It is really awesome!

    function onChange(e) {
        var date = Date.parse($("#DatePicker").val()); //You might want to tweak this to as per your needs.
        var new_date = date.add(n).days();
        $('.new').val(new_date.toString('M/d/yyyy'); //You might want to tweak this as per your needs as well.
    }
    

提交回复
热议问题