javascript 日期列中的剑道网格格式时间问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19316687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:08:43  来源:igfitidea点击:

Kendo grid format time issue in date column

javascriptdatekendo-uikendo-grid

提问by Jom

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}"

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

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

在模态中我使用了日期类型 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"

输出日期是 '10-Oct-2013 12:00:00 AM',但通过 ajax 调用返回的实际日期是 "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?

如何在 Grid 中显示正确的时间,例如 10-Oct-2013 05:02:40 AM?

回答by OnaBai

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.
  • format:指定格式,用于格式化输入中显示的DateTimePicker的值。
  • parseFormats:指定格式,用于解析 value() 方法或直接输入设置的值。

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

所以实际上你需要定义一个 parseFormat 因为T日期和时间之间使得格式不是默认格式:

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/

在这里运行示例:http: //jsfiddle.net/OnaBai/Ahq6s/

回答by Rich G

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"]
}

]

]