jQuery KendoUI 格式化日期和时间字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14932359/
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-08-26 14:06:18  来源:igfitidea点击:

KendoUI formatting date and time field

jquerykendo-uikendo-grid

提问by imperium2335

I am trying to turn a previously date only field to a date-time field but it is not working.

我正在尝试将以前的仅日期字段转换为日期时间字段,但它不起作用。

I have:

我有:

schema: {
    model: {
    id: 'id',
    fields: {
        dateCreated: {
        type: "date", format: "{0:yyyy/MM/dd HH:mm}", editable: "false"
        },
        ...
    }
}

But this doesn't work, the date comes out formatted properly but the time ends up being 00:00.

但这不起作用,日期格式正确,但时间最终为 00:00。

If I change the field type to "string" the data shows properly but is formatted the SQL way i.e:

如果我将字段类型更改为“字符串”,则数据显示正确,但格式为 SQL 方式,即:

2012-05-11 12:56:29

There is no such field type as "datetime", only "date". How do I get this to output how I want? i.e:

没有“日期时间”这样的字段类型,只有“日期”。我如何让它以我想要的方式输出?IE:

11/05/2012 12:56


Any one have any ideas?

谁有想法?

回答by napoleonss

You must use a template '#= kendo.toString(kendo.parseDate(dateCreated), 'MM/dd/yyyy HH:mm tt')#'

您必须使用模板 '#= kendo.toString(kendo.parseDate(dateCreated), 'MM/dd/yyyy HH:mm tt')#'

回答by VtoCorleone

Where are you trying to use this data? If you're using it in a grid, you can use the 'template' property in the column definition

你想在哪里使用这些数据?如果您在网格中使用它,则可以在列定义中使用 'template' 属性

var columnDefinition = [
    {
        field: "dateCreated",
        title: "Created",
        template: "#= kendo.toString(dateCreated,'MM/dd/yyyy HH:mm tt') #"
    }
];

Here's a fiddle with the formatting in a grid

这是一个关于网格格式的小提琴