如何将jQuery datepicker格式设置为dd-mm-year [英] How to set jQuery datepicker format to dd-mm-year

查看:118
本文介绍了如何将jQuery datepicker格式设置为dd-mm-year的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为以下内容

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

然后我有下面的jQuery:

I then have below 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"

But "18th March 2016" is coming up as "3/18/2016" and I was expecting this "18-03-2016"

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

How do I properly set my desired format of "18-03-2016" (day,month,year)?. Notice that I want the separator to be this - not /.

推荐答案

您尚未正确设置日期格式.这是一个有效的小提琴.基本上,您必须像下面这样设置dateFormat:

You have not set the date format correctly. Here is a working fiddle. Basically you have to set the dateFormat like below:

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

这篇关于如何将jQuery datepicker格式设置为dd-mm-year的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆