DateTimeFormat

Nov 30, 2010 at 12:03 PM

I'm trying to use custom date time format, but the converter uses always the default format.

Can someone give me a working example please?

-- 8< -- 8< --

 var converter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss.fffK" };
           
var jSonSettings = new JsonSerializerSettings
{
 ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(),
 Converters = new List<Newtonsoft.Json.JsonConverter> { converter }
};

-- 8< -- 8< --

 

Cheers,

-h


Nov 30, 2010 at 6:23 PM

Works fine for me.

var before = new WithDateTime { SomeTime = DateTime.UtcNow };
var json = JsonConvert.SerializeObject(before, Formatting.None, jSonSettings);
var after = JsonConvert.DeserializeObject<WithDateTime>(json, jSonSettings);

'json' is: {"someTime":"2010-11-30T18:22:33.441Z"}

- Ed