Home > Web Front-end > JS Tutorial > JavaScript Serializer serialization time processing example_javascript skills

JavaScript Serializer serialization time processing example_javascript skills

WBOY
Release: 2016-05-16 16:40:40
Original
1272 people have browsed it

JavaScriptSerializer序列化时间后会把时间序列化成N进制的鬼数据,于是查了下质料坐下记录

假设list = News List(){new Text(){id=1,date='2014-03-11 00:00:00.000'}}

JavaScriptSerializer serializable = new JavaScriptSerializer();
string json = serializable.Serialize(new { total = total, rows = list});
//使用正则表达式来替换被序列化的时间
json = System.Text.RegularExpressions.Regex.Replace(json, @"\\/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");
});
return json;
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template