JavaScript Serializer serializable time processing example

  • 2020-03-30 03:36:59
  • OfStack

JavaScriptSerializer serializes the time into n-base ghost data, and then checks the following material to sit down

Suppose list = News list < Text> {new Text () () {id = 1, the date = '2014-03-11 00:00:00. 000'}}


JavaScriptSerializer serializable = new JavaScriptSerializer();
string json = serializable.Serialize(new { total = total, rows = list});
//Replace the serialized time with a regular expression
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;

Related articles: