Share via


Deserialize Json Date string

We trace some objects in json format on live site. The json date string is not human readable so I found some code as below to do the translation work. One is in C# and the other is in javascript.

C# version (you will need to import Sysmte.Web.Extensions.dll)      

var serializer = new JavaScriptSerializer();    

string jsaon = "\\\/Date(1310075416697-0700)\\/\";       

DateTime dt = serializer.Deserialize<DateTime>(jsaon);

 

Just put the below content into an empty txt file and save it as .html and then open it in IE.

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="https://www.w3.org/1999/xhtml" >

<head><title>Untitled Page</title></head>

<body>

<script>

var value = "\/Date(1310075416697-0700)\/";

var date = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));

document.writeln(date);

</script></body></html>