【问题标题】:How to set the date format of the date displayed in kendo datepicker to the same format as the system?如何将kendo datepicker中显示的日期的日期格式设置为与系统相同的格式?
【发布时间】:2015-05-05 14:09:35
【问题描述】:

我在我的网络应用程序中使用kendo datePicker

其中显示的日期默认格式为MM/DD/YYYY

我想获取操作系统或浏览器使用的日期格式并将其应用于kendo datePicker

javascript中是否有方法或函数可以提供此功能?

【问题讨论】:

  • 您使用的是哪个库? jQuery 用户界面?引导日期选择器?

标签: javascript date kendo-ui


【解决方案1】:

由于你没有给我任何代码,你可以试试这个:

    td = new Date();
    var dd = today.getDate();
    var mm = today.getMonth()+1; //January is 0!
    var yyyy = today.getFullYear();

    if(dd<10) {
        dd='0'+dd
    } 

    if(mm<10) {
        mm='0'+mm
    } 

    td = dd+'/'+mm+'/'+yyyy;
   $(document).ready(function() {
                    var today = td,
                        birthdays = [
                           new Date(today.getFullYear(), today.getMonth(), 11),
                           new Date(today.getFullYear(), today.getMonth() + 1, 6),
                           new Date(today.getFullYear(), today.getMonth() + 1, 27),
                           new Date(today.getFullYear(), today.getMonth() - 1, 3),
                           new Date(today.getFullYear(), today.getMonth() - 2, 22)
                        ];

                    $("#datepicker").kendoDatePicker({
                        value: today,
                        dates: birthdays,
                         ....});

DatePicker 代码改编自here

编辑:我注意到您现在询问了系统日期。 我搜索了一下,发现了这个方法Date.prototype.toLocaleDateString()

根据this,您将获得以下格式:

例如2011 年 12 月 13 日对我来说:

  1. Safari 于 2001 年 12 月 13 日回归
  2. 火狐 12/13/2011
  3. 2011 年 12 月 13 日,星期二
  4. Chrome,2011 年 12 月 13 日,星期二
  5. IE 6 2011 年 12 月 13 日,星期二

但是,我没有测试它,所以请提供证据以防我错了

希望对你有帮助

【讨论】:

    【解决方案2】:

    您应该使用当前的文化来确定格式,使用Kendo Globalization

    确定当前文化:

    @{
        var culture = Thread.CurrentThread.CurrentCulture.Name;
    }
    

    添加剑道文化脚本:

    <script src="jquery.js"></script>
    <script src="kendo.all.min.js"></script>
    <script src="@Url.Content("~/Scripts/kendo/kendo.culture." + culture + ".min.js")"></script>  
    

    然后将当前文化应用于所有小部件:

    <script type="text/javascript">
        kendo.culture("@culture");
    </script>
    

    ...或者,基于每个小部件的硬编码。

    $("#firstDate").kendoDatePicker({
        culture: "en-GB",
        //....
    });
    

    取决于当前文化的小部件列表

    • 日历
    • 日期选择器
    • 时间选择器
    • 日期时间选择器
    • 数字文本框
    • MaskedTextBox(全球化掩码文字)
    • 调度器
    • 甘特图
    • 所有支持日期或数字格式的小部件。

    globalize.js:

    请注意,当 globalize.js 在 Kendo UI 脚本之前注册时,Kendo UI 将使用 globalize.js 功能而不是 Kendo UI 全球化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      相关资源
      最近更新 更多