I\'m not sure if it\'s me missing something - or IE or Json.Net.
But basically this works:
new Date(\"2012-08-03T12:36:54.743Z\")
This f
It's IE. The most comprehensive explaination and answer I found is at JavaScript: Which browsers support parsing of ISO-8601 Date String with Date.parse
In particular
IE9 was failing on milliseconds with digit counts other than 3: (fixed in IE10)
I can't tell you whether it is intended or not, but I've done a lot of searching and I haven't found a real solution for this issue neither. It seems that we have to accept the fact that IE only accepts exactly three digits. The only way (for me) to get around this issue is to use a custom converter for Json.NET when serializing:
string json = JsonConvert.SerializeObject(
whatEver,
new IsoDateTimeConverter
{
DateTimeFormat = "yyyy-MM-dd\\THH:mm:ss.fffK"
}
);
(only tested with Json.NET 4.0.8 and 4.5.8)
This forces Json.NET to use exactly 3 decimal places.
As far as I can tell, Json.NET serializes DateTime
values in ISO format with the maximum necessary precision omitting trailing zeroes in the decimal places of the "second" value.
This matches the output of
someDateTimeValue.ToString("yyyy-MM-dd\\THH:mm:ss.FFFFFFFK")
DateTime
like DateTime.UtcNow
will be serialized with up to 7 digits, because that is the precision of a DateTime
(measured in Ticks).DateTime
has less decimal places, Json.NET omits those trailing zeroes.DateTime.Today
will therefore contain no digits behind the "second" value because it is exactly 0
.See also this description of custom date and time format strings.