本文介绍了jqgrid datetime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring MVC Java应用程序,并且正在将joda DateTime序列化为json.

I have a spring MVC java application and I'm serializing joda DateTime to json.

当我通过浏览器检查输出时,DateTime序列化的数据如下所示:

When I examine the output through the browser the DateTime serialized data looks like this:

startDate: 1323147660000

我不确定该数据采用哪种格式.我已经尝试过srcformat和newformat格式选项的许多不同组合,包括基于:

I'm not sure which format this data is in. I've tried many different combinations of srcformat and newformat format options including the following based on this post:

{srcformat:'U', newformat:'m/d/Y'}

我的直觉是这是自该纪元以来的毫秒数,但我不确定如何在jqgrid中正确使用它.

My hunch is that this is the number of milliseconds since the epoch but I'm not sure how to use it correctly within jqgrid.

在此先感谢您的帮助.

推荐答案

实际上,在早期版本的jqGrid中,开箱即用地支持从纪元格式开始的毫秒数.不幸的是,由于未知原因,它已被删除.

Actually the milliseconds from epoch format was supported out-of-the-box in one of the previous versions of jqGrid. Unfortunately it has been dropped for an unknown reason.

这是一种解决方法:

{
    name:'startDate',
    label: 'Start date'
    formatter: function(cellValue, options) {
        if(cellValue) {
            return $.fmatter.util.DateFormat(
                '',
                new Date(+cellValue),
                'UniversalSortableDateTime',
                $.extend({}, $.jgrid.formatter.date, options)
            );
        } else {
            return '';
        }
    }
}

请注意,使用自定义formatter可以解析日期并以所需的任何方式对其进行格式化.但是,我尽力使用内置的jqGrid格式化工具(请参见UniversalSortableDateTime?)

Note that with custom formatter you can parse the date and format it in any way you wish. However I did my best to use built-in jqGrid formatting facilities (see the UniversalSortableDateTime?)

这篇关于jqgrid datetime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:40