如何在当前日期添加10天?

时间:2017-05-13 13:14:36

标签: javascript date datepicker

我有实现日历的代码:

$( function() {
    var dateFormat = "mm/dd/yy",
    from = $( "#fromdate" ).datepicker({
        minDate:0,
        changeMonth: true
    }).on( "change", function() {
        to.datepicker( "option", "minDate", getDate( this ) );
    }),
    to = $( "#todate" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true
    }).on( "change", function() {
        from.datepicker( "option", "minDate", getDate( this ) );
    });

    function getDate( element ) {
        var date;
        try {
            date = $.datepicker.parseDate( dateFormat, element.value );
        } catch( error ) {
            date = null;
        }
        return date;
    }
});

我有#fromdate#todate HTML元素。我希望#fromdate选择当前日期(它会这样做),并#todate添加10天(这不起作用),并在日历上显示。

1 个答案:

答案 0 :(得分:-1)

试试这段代码

$date = strtotime($date);
$date = strtotime("+10 day", $date);
echo date('M d, Y', $date);