json转换后时间格式处理
var str = new JavaScriptSerializer().Serialize(borrowCar);
//此时时间的格式为时间戳
{
"Base": "大连",
"SeriesNo": "XZB-JCSQD-2017110003",
"UserCode": "XXXXX",
"Operate": "A",
"VehicleStat": [
{
"Type": "L",
"Reason": "123123",
"StartTime": "/Date(1511280000000)/",
"EndTime": "/Date(1511452800000)/"
},
{
"Type": "D",
"Reason": "123123",
"StartTime": "/Date(1511452800000)/",
"EndTime": "/Date(1511539200000)/"
},
{
"Type": "L",
"Reason": "22",
"StartTime": "/Date(1511452800000)/",
"EndTime": "/Date(1511452800000)/"
}
]
}
//通过正则处理
str = Regex.Replace(str, @"\\/Date\((\d+)\)\\/", match =>
{
DateTime dt = new DateTime(1970, 1, 1);
dt = dt.AddMilliseconds(long.Parse(match.Groups[1].Value));
dt = dt.ToLocalTime();
return dt.ToString("yyyy-MM-dd HH:mm:ss");
});
//处理后的结果
{
"Base": "大连",
"SeriesNo": "XZB-JCSQD-2017110003",
"UserCode": "XXX",
"Operate": "A",
"VehicleStat": [
{
"Type": "L",
"Reason": "123123",
"StartTime": "2017-11-22 00:00:00",
"EndTime": "2017-11-24 00:00:00"
},
{
"Type": "D",
"Reason": "123123",
"StartTime": "2017-11-24 00:00:00",
"EndTime": "2017-11-25 00:00:00"
},
{
"Type": "L",
"Reason": "22",
"StartTime": "2017-11-24 00:00:00",
"EndTime": "2017-11-24 00:00:00"
}
]
}