Adding “st, nd, rd, th” to jquery datepicker

后端 未结 8 500
臣服心动
臣服心动 2020-12-11 15:44

How can I add st,nd,rd,th to date format.. i.e. November 19th, or December 2nd, etc.

Currently, I have following code

    $( \"#datepicker\" ).datepi         


        
8条回答
  •  醉梦人生
    2020-12-11 16:28

    dateFormat doesn't use "s" as a format type, so in the options I usually add -

    dateFormat : "DD ds MM, yy",
    onSelect: function(dateText, inst) {
        var arrOrd = new Array('0','st','nd','rd','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','st','nd','rd','th','th','th','th','th','th','th','st');
        var day = Number(inst.selectedDay);
        var suffix = arrOrd[day];       
        $(this).val($(this).val().replace(inst.selectedDay+"s",inst.selectedDay+suffix));
    }
    

提交回复
热议问题