duanqiu2064
duanqiu2064
2014-02-18 15:53

datepicker自定义日期更改格式

  • php
  • javascript
  • jquery

i have a working cusom button 'CSA' to display todays date + 6 months, but the date gets displayed as 2014-8-18. Now what i wish is 2014-08-18 and this for every month, 2 digits for every month.... working jsfiddle

    $(function () {
        $(".datepicker").datepicker({
            dateFormat: "yy-mm-dd",
            changeMonth: true,
            changeYear: true,
            yearRange: "2014:2034",
            showButtonPanel: true,
            beforeShow: function (input) {
                setTimeout(function () {
                    var buttonPane = $(input)
                        .datepicker("widget")
                        .find(".ui-datepicker-buttonpane");

                    var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">CSA</button>');
                    btn.unbind("click")
                        .bind("click", function () {
                            //$.datepicker._clearDate(input);
                            //alert('custom text');
                            $(input).datepicker("hide");
                            var date = new Date();
                            date.setMonth(date.getMonth() + 7);
                            $(input).val(date.getFullYear() + '-' +
                                date.getMonth() + '-' + date.getDate());

                        });


                    btn.appendTo(buttonPane);

                }, 1);
            }
        });

});
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐