2012-11-30 26 views

回答

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 
6

所有您需要进行的转换是在jqGrid柱模型中设置date格式化程序:

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

对于newformat选项jqGrid支持PHP date formatting