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"
}
]
}

posted @ 2017-11-22 15:47  D调灬仔  阅读(730)  评论(0编辑  收藏  举报

作者D调灬仔

出处:https://www.cnblogs.com/chj929555796/

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!