That's not a valid JSON representation of a date.
Assuming you're trying to generate a Javascript snippet to construct a new
Date
, you need to bear in mind that the month you pass in is the month
index: January =
0
, February =
1
, etc. So
new Date(2021,5,21)
represents 21st
June, not 21st May.
Date() constructor - JavaScript | MDN[
^]
JSON.NET has a built-in converter to generate a correct Javascript snippet for you, even though it's not technically correct JSON:
Serializing Dates in JSON[
^]
var jsonSettings = new JsonSerializerSettings
{
Converters =
{
new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter(),
},
};
string jsonKalin = JsonConvert.SerializeObject(dmKalin, jsonSettings);
The number passed to the
Date
constructor represents the number of milliseconds since the UNIX epoch.