Click or drag to resize
Json.NET

DateFormatHandling setting

 

This sample uses the DateFormatHandling setting to control how DateTime and DateTimeOffset are serialized.

Sample
Usage
DateTime mayanEndOfTheWorld = new DateTime(2012, 12, 21);

string jsonIsoDate = JsonConvert.SerializeObject(mayanEndOfTheWorld);

Console.WriteLine(jsonIsoDate);
// "2012-12-21T00:00:00"

string jsonMsDate = JsonConvert.SerializeObject(mayanEndOfTheWorld, new JsonSerializerSettings
{
    DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
});

Console.WriteLine(jsonMsDate);
// "\/Date(1356044400000+0100)\/"