在JqGrid显示日期时间../日期(1352658600000)/

时间:2012-11-30 11:16:30

标签: asp.net-mvc-3 jqgrid

/Date(1352658600000)/ 

显示日期时日期未以正确格式显示。

如何转换为正确的Format(dd/mm/yyyy)

2 个答案:

答案 0 :(得分:6)

您需要进行转换,只需在jqGrid列模型中设置date格式化程序:

$('#gridId').jqGrid({
    ...
    colModel: [
        ...
        { name: 'Column Name', index: 'Column Index', ..., formatter: "date", formatoptions: { newformat: "m/d/Y"} },
        ...
    ],
    ...
});

对于newformat选项,jqGrid支持PHP date formatting

答案 1 :(得分:1)

取自此处接受的答案 - Converting json results to a date

您需要从字符串中提取数字,并将其传递给Date构造函数:

var x = [ {"id":1,"start":"\/Date(1238540400000)\/"}, {"id":2,"start":"\/Date(1238626800000)\/"} ];

var myDate = new Date(x[0].start.match(/\d+/)[0] * 1));

部分是:

x[0].start                                - get the string from the JSON
x[0].start.match(/\d+/)[0]                - extract the numeric part
x[0].start.match(/\d+/)[0] * 1            - convert it to a numeric type
new Date(x[0].start.match(/\d+/)[0] * 1)) - Create a date object
相关问题