We want to show some JSON to a user who is testing our application. So we call our REST service in the ASP.NET code behind file and return a string, which holds a lot of JSON.
We then put it in a PRE element in the page, call beautify to create nice readable JSON and all is good: sort of human readable content is shown.
Good but for one thing: all the dates are shown in the normal JSON format like this “/Date(1319266795390+0800)/”
What I want to do is replace those JSON dates with ‘normal’ dates, in the JSON (C#) string, so in the code behind that is, before I add the string to the PRE element.
I was thinking about some regex, but i couldn’t figure out how…
The solution is within the string shown in the question. The JavaScript Date object will parse that format and produce a readable version so
Date(1319266795390+0800)returns “Wed Apr 18 2012 08:13:22 GMT-0500 (Central Daylight Time)”.To remove the forward slash from the string you could use the replace function with a regular expression:
"/Date(1319266795390+0800)/".replace(/\//g, '').