<p>Given the following JSON Date representation:</p>

<pre><code>"\/Date(1221644506800-0700)\/"
</code></pre>

<p>How do you deserialize this into it's JavaScript Date-type form?</p>

<p>I've tried using MS AJAX JavaScrioptSerializer as shown below:</p>

<pre><code>Sys.Serialization.JavaScriptSerializer.deserialize("\/Date(1221644506800-0700)\/")
</code></pre>

<p>However, all I get back is the literal string date.</p>

[{'answer_id': 82244, 'author': 'Daniel', 'author_id': 6852, 'author_profile': 'https://Stackoverflow.com/users/6852', 'pm_score': 1, 'selected': False, 'text': '<p>The big number is the standard JS time</p>\n\n<pre><code>new Date(1221644506800)\n</code></pre>\n\n<p>Wed Sep 17 2008 19:41:46 GMT+1000 (EST)</p>\n'}, {'answer_id': 82377, 'author': 'Sjoerd Visscher', 'author_id': 5852, 'author_profile': 'https://Stackoverflow.com/users/5852', 'pm_score': 4, 'selected': False, 'text': '<p>A JSON value is a string, number, object, array, true, false or null. So this is just a string. There is no official way to represent dates in JSON. This syntax is from the asp.net ajax implementation. Others use the ISO 8601 format.</p>\n\n<p>You can parse it like this:</p>\n\n<pre><code>var s = "\\/Date(1221644506800-0700)\\/";\nvar m = s.match(/^\\/Date\\((\\d+)([-+]\\d\\d)(\\d\\d)\\)\\/$/);\nvar date = null;\nif (m)\n  date = new Date(1*m[1] + 3600000*m[2] + 60000*m[3]);\n</code></pre>\n'}, {'answer_id': 428857, 'author': 'Kyle Jones', 'author_id': 53424, 'author_profile': 'https://Stackoverflow.com/users/53424', 'pm_score': 3, 'selected': False, 'text': '<p>The regular expression used in the ASP.net AJAX deserialize method looks for a string that looks like "/Date(1234)/" (The string itself actually needs to contain the quotes and slashes). To get such a string, you will need to escape the quote and back slash characters, so the javascript code to create the string looks like "\\"\\/Date(1234)\\/\\"".</p>\n\n<p>This will work.</p>\n\n<pre><code>Sys.Serialization.JavaScriptSerializer.deserialize("\\"\\\\/Date(1221644506800)\\\\/\\"")\n</code></pre>\n\n<p>It\'s kind of weird, but I found I had to serialize a date, then serialize the string returned from that, then deserialize on the client side once.</p>\n\n<p>Something like this.</p>\n\n<pre><code>Script.Serialization.JavaScriptSerializer jss = new Script.Serialization.JavaScriptSerializer();\nstring script = string.Format("alert(Sys.Serialization.JavaScriptSerializer.deserialize({0}));", jss.Serialize(jss.Serialize(DateTime.Now)));\nPage.ClientScript.RegisterStartupScript(this.GetType(), "ClientScript", script, true);\n</code></pre>\n'}, {'answer_id': 959092, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 6, 'selected': True, 'text': '<p>Provided you know the string is definitely a date I prefer to do this :</p>\n\n<pre><code> new Date(parseInt(value.replace("/Date(", "").replace(")/",""), 10))\n</code></pre>\n'}, {'answer_id': 1646987, 'author': 'Alex Nolasco', 'author_id': 65694, 'author_profile': 'https://Stackoverflow.com/users/65694', 'pm_score': 2, 'selected': False, 'text': '<p>For those who don\'t want to use Microsoft Ajax, simply add a prototype function to the string class.</p>\n\n<p>E.g.</p>\n\n<pre><code>    String.prototype.dateFromJSON = function () {\n    return eval(this.replace(/\\/Date\\((\\d+)\\)\\//gi, "new Date($1)"));\n};\n</code></pre>\n\n<p>Don\'t want to use eval? Try something simple like</p>\n\n<pre><code>var date = new Date(parseInt(jsonDate.substr(6)));\n</code></pre>\n\n<p>As a side note, I used to think Microsoft was misleading by using this format. However, the JSON specification is not very clear when it comes to defining a way to describe dates in JSON.</p>\n'}, {'answer_id': 2654571, 'author': 'ESV', 'author_id': 150, 'author_profile': 'https://Stackoverflow.com/users/150', 'pm_score': 4, 'selected': False, 'text': '<p>Bertrand LeRoy, who worked on ASP.NET Atlas/AJAX, <a href="http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx" rel="noreferrer">described the design of the JavaScriptSerializer DateTime output</a> and revealed the origin of the mysterious leading and trailing forward slashes.  He made this recommendation:</p>\n\n<blockquote>\n  <p>run a simple search for "\\/Date((\\d+))\\/" and replace with "new Date($1)" before the eval\n  (but after validation)</p>\n</blockquote>\n\n<p>I implemented that as:</p>\n\n<pre><code>var serializedDateTime = "\\/Date(1271389496563)\\/";\ndocument.writeln("Serialized: " + serializedDateTime + "&lt;br /&gt;");\n\nvar toDateRe = new RegExp("^/Date\\\\((\\\\d+)\\\\)/$");\nfunction toDate(s) {\n    if (!s) {\n        return null;\n    }\n    var constructor = s.replace(toDateRe, "new Date($1)");\n    if (constructor == s) {\n        throw \'Invalid serialized DateTime value: "\' + s + \'"\';\n    }\n    return eval(constructor);\n}\n\ndocument.writeln("Deserialized: " + toDate(serializedDateTime) + "&lt;br /&gt;");\n</code></pre>\n\n<p>This is very close to the many of the other answers:</p>\n\n<ul>\n<li>Use an anchored RegEx as Sjoerd Visscher did -- don\'t forget the ^ and $.</li>\n<li>Avoid string.replace, and the \'g\' or \'i\' options on your RegEx.  "/Date(1271389496563)//Date(1271389496563)/" shouldn\'t work at all.</li>\n</ul>\n'}, {'answer_id': 41367697, 'author': 'tavo', 'author_id': 3545581, 'author_profile': 'https://Stackoverflow.com/users/3545581', 'pm_score': 2, 'selected': False, 'text': '<p>Actually, momentjs supports this kind of format, you might do something like:</p>\n\n<pre><code>    var momentValue = moment(value);\n\n    momentValue.toDate();\n</code></pre>\n\n<p>This returns the value in a javascript date format</p>\n'}]
['https://Stackoverflow.com/questions/82058', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9275/']