Can you tell JSON.Net to serialize DateTime as Utc even if unspecified?

前端 未结 5 971
遇见更好的自我
遇见更好的自我 2020-11-29 03:45

Dates in my database are stored as Utc. But when I retreieve them w/ the entity framework they come out as type unspecified.

When JSON.Net serializes them they are n

5条回答
  •  [愿得一人]
    2020-11-29 04:18

    I used the accepted answer however applied to the default settings:

            JsonConvert.DefaultSettings = (() =>
            {
                var settings = new JsonSerializerSettings();
                settings.Converters.Add(new StringEnumConverter());
                settings.Formatting = Formatting.Indented;
                settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                return settings;
            });
    

提交回复
热议问题