Serialize DateFormatString |
This sample uses the DateFormatString setting to control how DateTime and DateTimeOffset are serialized.
IList<DateTime> dateList = new List<DateTime> { new DateTime(2009, 12, 7, 23, 10, 0, DateTimeKind.Utc), new DateTime(2010, 1, 1, 9, 0, 0, DateTimeKind.Utc), new DateTime(2010, 2, 10, 10, 0, 0, DateTimeKind.Utc) }; string json = JsonConvert.SerializeObject(dateList, new JsonSerializerSettings { DateFormatString = "d MMMM, yyyy", Formatting = Formatting.Indented }); Console.WriteLine(json); // [ // "7 December, 2009", // "1 January, 2010", // "10 February, 2010" // ]