Kendo grid format time issue in date column [duplicate]

。_饼干妹妹 提交于 2019-12-01 06:07:54

问题


I have a kendo grid, it has a date column. I want to show date and time there. I am using below format in column definition,

format: "{0:dd-MMM-yyyy hh:mm:ss tt}"

In modal I used date type Updated_Date: { type: "date" }

Output date is coming as '10-Oct-2013 12:00:00 AM', but actual date returned via ajax call is "Updated_Date":"2013-10-10T05:02:40.44"

What to do to show the correct time in Grid like 10-Oct-2013 05:02:40 AM?


回答1:


There are two fields that are commonly confused:

  • format : Specifies the format, which is used to format the value of the DateTimePicker displayed in the input.
  • parseFormats: Specifies the formats, which are used to parse the value set with value() method or by direct input.

So actually you need to define a parseFormat because of the T between date and time that makes the format not being a default one:

Try:

columns   : [
    ...
    {
        field       : "Date",
        title       : "Date",
        format      : "{0:dd-MMM-yyyy hh:mm:ss tt}",
        parseFormats: ["yyyy-MM-dd'T'HH:mm:ss.zz"]
    }
]

Running example here : http://jsfiddle.net/OnaBai/Ahq6s/




回答2:


Just had the exact same problem. It is because the grid is not recognising the field as a date. You need to add the "type" as follows:

columns   : [
...
{
    field       : "Date",
    title       : "Date",
    type        : "date",
    format      : "{0:dd-MMM-yyyy hh:mm:ss tt}",
    parseFormats: ["yyyy-MM-dd'T'HH:mm:ss.zz"]
}

]



来源:https://stackoverflow.com/questions/19316687/kendo-grid-format-time-issue-in-date-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!