WebApi Json.NET custom date handling

前端 未结 2 1420
北海茫月
北海茫月 2020-12-01 16:47

I have globally explicitly configured my MVC4 app to use the JSON.NET serializer . I know i have the choice of using the ISO standard dates or the old Microsoft date format

2条回答
  •  自闭症患者
    2020-12-01 17:16

    Change your setting set up code like this:

    JsonMediaTypeFormatter jsonFormatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
    JsonSerializerSettings jSettings = new Newtonsoft.Json.JsonSerializerSettings()         
    {
        Formatting = Formatting.Indented,
        DateTimeZoneHandling = DateTimeZoneHandling.Utc
    };
    jSettings.Converters.Add(new MyDateTimeConvertor());
    jsonFormatter.SerializerSettings = jSettings;
    

    In your code you are just changing local variable value.

提交回复
热议问题