.NET中的JavaScriptSerializer可以提供序列化和反序列化(要使用它,请在头部引用 using System.Web.Script.Serialization;)
序列化日期格式后的JSON字符串显示为“/Date(700000_0500)/”形式的JSON字符串,其中第一个数字(在提供的示例中为 700000)是 GMT 时区中自 1970 年 1 月 1 日午夜以来按正常时间(非夏令时)经过的毫秒数。该数字可以是负数,以表示之前的时间。示例中包括“+0500”的部分可选,它指示该时间属于Local类型,即它在反序列化时应转换为本地时区。如果没有该部分,则会将时间反序列化为Utc。
怎么处理这个日期格式,两种方法,一种是在后台处理成字符串型正常日期,再传到前台。第二种方法是传到前台后用javascript处理。
这里说一下第二种方法:
function changFormat(value){
if (value == undefined || value == "") {
return "";
}
var temp=value.replace("/Date(", "");
temp=temp.replace(")/", "");
var date = new Date(parseInt(temp));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate;
}
columns: [[
{title: 'id号', field: 'JY_ID', width: 5, hidden: true },
{ title: '轮班', field: 'LB', width: 30, align: 'right' },
{ title: '送样时间', field: 'SY_TIME', width: 100, align: 'center',
formatter: function (value, rowData, rowIndex) {
if (value == undefined || value == "") {
return "";
}
var temp=value.replace("/Date(", "");
temp=temp.replace(")/", "");
var date = new Date(parseInt(temp));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate;
}
},
{ title: '取样地点', field: 'QYDD', width: 120 },
]],