Coercing Json Serializer into producing a particular datetime format (yyyy-mm-ddThh:mm:ss.msmsmsZ)

Posted by Chris McCall on Stack Overflow See other posts from Stack Overflow or by Chris McCall
Published on 2010-03-12T19:22:17Z Indexed on 2010/03/12 19:27 UTC
Read the original article Hit count: 368

Filed under:
|
|
|
MyClass theSession = new MyClass()
                {
                    accountId = 12345,
                    timeStamp = DateTime.Now,
                    userType = "theUserType"
                };

System.Web.Script.Serialization.JavaScriptSerializer Json = new System.Web.Script.Serialization.JavaScriptSerializer();
        Response.Write(Json.Serialize(theSession));

Produces:

{"accountId":12345,"timeStamp":"\/Date(1268420981135)\/","userType":"theUserType"}

How can I present the date as:

"timestamp":"2010-02-15T23:53:35.963Z"

?

© Stack Overflow or respective owner

Related posts about c#

Related posts about jsonserializer