如何将jQuery datepicker格式设置为dd-mm-year

时间:2016-03-18 07:12:27

标签: javascript jquery datepicker

我认为我有以下内容:

<input type="text" name="Model.Date" value="@Model.DateOfAction.ToShortDateString()"  class="txtDate" readonly = "readonly" style = "width: 90px; padding: 0px;" />

然后我在jQuery下面:

$(document).ready(function() {
    $(document.getElementsByClassName(".txtDate")).each(function () {
        $(this).datepicker({
            dateFormat: 'dd-mm-yy',
            showButtonPanel: true,
            changeMonth: true,
            changeYear: true,
            defaultDate: new Date(),
        });
    });
});

"18th March 2016"即将出现"3/18/2016",我期待"18-03-2016"

如何正确设置所需格式"18-03-2016"(日,月,年)?请注意,我希望分隔符为-而不是/

2 个答案:

答案 0 :(得分:2)

您尚未正确设置日期格式。这是一个有效的fiddle。基本上你必须设置如下dateFormat

$(function() {
    $('.txtDate').datepicker({
            dateFormat: 'dd-mm-yy',
            showButtonPanel: true,
            changeMonth: true,
            changeYear: true,
            defaultDate: new Date()
        });
  });

答案 1 :(得分:1)

 $(document).ready(function() {
     $(document.getElementsByClassName(".txtDate")).each(function () {
        $(this).datepicker({
            dateFormat: 'dd-mm-yy',
            showButtonPanel: true,
            changeMonth: true,
            changeYear: true,
            defaultDate: new Date(),
        });});
});