Prevent Json.NET 4.5 from appending timezone offset when using MicrosoftDateFormat

前端 未结 2 524
攒了一身酷
攒了一身酷 2021-02-12 13:44

Short of a custom DateTimeConverterBase implementation, is there some way to keep Json.NET 4.5+, when set to use DateFormatHandling.MicrosoftDateFormat

2条回答
  •  清歌不尽
    2021-02-12 14:26

    I found a solution to remove timezone offset from DateTime for latest version 9.0.0:

    var time = DateTime.Now;
    
    Console.WriteLine(JsonConvert.SerializeObject(time, new JsonSerializerSettings()
    {
        DateFormatHandling = DateFormatHandling.IsoDateFormat,
        DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Unspecified
    }));
    
    //"{"thedate": "2016-12-15T09:20:00.9375403"};
    

提交回复
热议问题