如何格式化Jquery Jtable日期字段编辑问题?

huangapple 未分类评论55阅读模式
英文:

How to format Jquery Jtable date field edit problem?

问题

我有一个使用jQuery的jtable,从Java Hibernate的pojo获取日期并转换为JSON,然后自动转换为如下格式:Apr 7, 2020 12:00:00 AM。
在我的jtable中,该字段的显示格式设置为'dd-MMM-yyyy',但我遇到了以下错误:

> jTable警告:给定的日期格式不正确:Apr 7, 2020
> 12:00:00 AM

只有在字段类型为日期时才会出现这种情况。

这仅发生在字段类型为日期时。

start_date: {
title: 'Date',
type: 'date',
displayFormat: 'dd-MMM-yyyy',
list: true,
width: '8%'
}

有人能帮我修复格式吗?我在pojo中尝试了相同的操作,但没有起作用。

英文:

I have a jtable jquery where I get the date from javahibernate pojo change to json and it gets auto change to this format Apr 7, 2020 12:00:00 AM.
In my jtable the display format for the field is set to 'dd-MMM-yyyy' I get the following error:

> jTable WARNING: Given date is not properly formatted: Apr 7, 2020
> 12:00:00 AM

This only happens when the field type is date

 start_date: {
	             title: 'Date',
	             type: 'date',
		         displayFormat:'dd-MMM-yyyy',
		         list: true,
	             width: '8%'
	            }

Can anyone help me to get the formatting fixed? I tried the same in pojo but it's not working.

答案1

得分: 0

使用 moment jQuery 库。
这是我已经完成的更改日期格式的操作。

       date: {
            title: 'Date',
            display: function(data) {
                return moment(data.record.timestamp).format('YYYY-MM-DD');
            },
        },
英文:

Use moment jquery library.
This is what I have done to change the date format.

       date: {
            title: 'Date',
            display: function(data) {
                return moment(data.record.timestamp).format('YYYY-MM-DD');
            },
        },

huangapple
  • 本文由 发表于 2020年6月6日 00:30:55
  • 转载请务必保留本文链接:https://java.coder-hub.com/62220081.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定