【问题标题】:Date Format incorrect after select date选择日期后日期格式不正确
【发布时间】:2016-03-21 13:51:02
【问题描述】:

我正在使用 (k-format = "dd/MM/yyyy") 设置 kendo-date-picker 的日期格式,因此,在选择日期后,格式不受尊重。我尝试使用 (k-options ="dateTimePickerOptions") 制作

$scope.dateTimePickerOptions = { 格式:“dd/MM/yyyy”}

它有效,但在向服务器发送数据之前,我检查了范围内的数据,console.log 返回“无效日期”。

这是我的完整代码:

输入名称="数据" kendo-date-picker ng-model="item.Data" k-ng-model="dateObject" style="width: 100%;" placeholder="选择一个 日期”k-options =“dateTimePickerOptions”k-解析格式 ="['yyyy-MM-ddTHH:mm:sszzz']" 必填 />

谁能帮帮我?

【问题讨论】:

    标签: kendo-ui


    【解决方案1】:

    这样试试

    <script>
        jQuery.extend(jQuery.validator.methods, {
            date: function (value, element) {
                return this.optional(element) || kendo.parseDate(value, "dd/MM/yyyy") != null;
            }
        });
    
    </script>
    

    查看

    @{
        ViewBag.Title = "Home Page";
    }
    @model DatePickerValidation.Models.ViewModel
    
    @using (Html.BeginForm())
    {
        @( 
            Html.Kendo().DatePickerFor(model => model.MyDate).Format("dd/MM/yyyy")
            .ParseFormats(new List<string>()
                            {
                            "dd/MM/yyyy",
                            "dd/MM/yy",
                            "dd MMM yyyy"
                            })
            .HtmlAttributes(new { @class = "k-datetimepicker" })
        )
        @Html.ValidationMessageFor(model => model.MyDate)
    
        <input type="submit" value="Submit" />
    }
    

    视图模型

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace DatePickerValidation.Models
    {
        public class ViewModel
        {
            public DateTime MyDate { get; set; }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-09
      • 2023-04-09
      • 2015-01-25
      • 2020-05-31
      • 1970-01-01
      • 2014-04-22
      • 2018-07-27
      相关资源
      最近更新 更多