【发布时间】:2012-11-18 14:40:34
【问题描述】:
/Date(1352658600000)/
当显示日期时,日期未以正确格式显示。
如何转换成正确的Format(dd/mm/yyyy)?
【问题讨论】:
-
您想在客户端还是服务器上执行此操作,使用哪种语言?
-
Asp.Net MVC 3.0 和客户端......
标签: asp.net-mvc-3 jqgrid
/Date(1352658600000)/
当显示日期时,日期未以正确格式显示。
如何转换成正确的Format(dd/mm/yyyy)?
【问题讨论】:
标签: asp.net-mvc-3 jqgrid
取自此处接受的答案 - 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
【讨论】:
您只需在 jqGrid 列模型中设置 date 格式化程序即可:
$('#gridId').jqGrid({
...
colModel: [
...
{ name: 'Column Name', index: 'Column Index', ..., formatter: "date", formatoptions: { newformat: "m/d/Y"} },
...
],
...
});
对于newformat 选项,jqGrid 支持PHP date formatting。
【讨论】: