2

Closed

IsoDateTimeConverter doesn't properly serialize milliseconds

description

I'm seeing the IsoDateTimeConverter serialize DateTimes in strings such as this:
 
"2012-06-07T19:46:30.62"
 
Various sources on the internet (I can't find the actual ISO8601 spec, strangely) specify that the milliseconds portion must be 3 digits, not two. And, in fact if you use Internet Explorer's built-in Date.parse function, it will fail on the above format, but succeeds with the trailing zero.
 
So, I think the IsoDateTimeConverter should be modified to include 3 digits of precision to match the spec (and avoid headaches with people trying to use DateTimes returned to the browser via a JSON-based API).
Closed Jul 25, 2012 at 6:30 AM by JamesNK
IsoDateTimeConverter is mostly there for backwards comparability but if you need to change DateTimeFormat.

comments

pmoriarity wrote Jun 15, 2012 at 10:27 PM

This worked for me until they fix it.
        var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;

        IsoDateTimeConverter iso = new IsoDateTimeConverter();
        iso.DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffK";

        if (formatter != null) 
        {    
            formatter.SerializerSettings = new JsonSerializerSettings() 
            {
                Converters = new JsonConverter[] { iso }        
            };
        }

robcube wrote Jan 9, 2013 at 10:43 PM

to me, this is still broken even with the latest Json.NET converter. The above fix by pmoriarity cinched it!