如何将 JQuery 日期选择器的格式更改为 MM/DD/YYYY

How to change the format of JQuery Date Picker to MM/DD/YYYY

基于此link

如果我想更改我的日期格式,我会去这里

defaults: {
    formatDate: function(date) {
        var formatted = $.datePicker.utils.pad(date.getDate(), 2) + '/' + $.datePicker.utils.pad(date.getMonth() + 1, 2) + '/' + date.getFullYear();
        return formatted;
    },
    parseDate: function(string) {
        var date = new Date();
        var parts = string.match(/(\d{1,2})\/(\d{1,2})\/(\d{4})/);
        if ( parts && parts.length == 4 ) {
            date = new Date( parts[3], parts[2] - 1, parts[1] );
        }
        return date;
    },
    selectDate: function(date) {
        return true;
    },
    limitCenturies: true,
    closeOnPick: true,
    appendTo: null
},

我怎样才能达到 MM/DD/YYYY?我尝试了一切我改变它但是当我选择日期时值在不同的日期出现

这里是错误

Try这出

var date = new Date('2014-01-06');
var newDate = date.toString('dd-MM-yy');

根据 documentation,这应该有效:

    defaults: {
        formatDate: function(date) {
    //var formatted = $.datePicker.utils.pad(date.getDate(), 2) + '/' + $.datePicker.utils.pad(date.getMonth() + 1, 2) + '/' +  date.getFullYear();
            var formatted = $.datePicker.utils.pad(date.getMonth() + 1, 2) + '/' + $.datePicker.utils.pad(date.getDate(), 2) + '/' + date.getFullYear();

            return formatted;
        },
        parseDate: function(string) {
            var date = new Date();

            if ( string ) {
                formatted_date = string.split('/');
                date = new Date( formatted_date[2], formatted_date[0] - 1, formatted_date[1] );
            }

            return date;
        },
        selectDate: function(date) {
            return true;
        },
        limitCenturies: true,
        closeOnPick: true,
        appendTo: null
    }

查看实际效果:Demo