【问题标题】:KendoUI formatting date and time fieldKendo UI 格式化日期和时间字段
【发布时间】:2013-02-02 15:37:19
【问题描述】:

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

我有:

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

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

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

2012-05-11 12:56:29

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

11/05/2012 12:56

有人有什么想法吗?

【问题讨论】:

    标签: jquery kendo-ui kendo-grid


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您打算在哪里使用这些数据?如果您在网格中使用它,则可以在列定义中使用“模板”属性

      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

      【讨论】:

      • 我试过了,但没用 :( 我最终在 SQL 中预先格式化了我的日期,使用 DATE_FORMAT 将日期导出。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      相关资源
      最近更新 更多