Obsługa niestandardowej daty WebApi Json.NET

Na całym świecie jawnie skonfigurowałem moją aplikację MVC4 do korzystania z serializatora JSON.NET. Wiem, że mam wybór używania standardowych dat ISO lub starego formatu daty Microsoft podczas serializacji dat.

Ale jak mogę wygenerować własny niestandardowy ciąg formatu dateTime, taki jak: „dd / MM / rrrr hh: mm”.

Mógłbym to zrobić w MVC3 podczas podłączania Json.NET jako domyślnego serializatora, ale nie wydaje się, aby robił to w MVC4.

Do tej pory w starcie aplikacji zrobiłem:

  var settings =     GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;            
        JsonSerializerSettings jSettings = new Newtonsoft.Json.JsonSerializerSettings()
        {
            Formatting = Formatting.Indented,
            DateTimeZoneHandling = DateTimeZoneHandling.Utc,


        };
        jSettings.Converters.Add(new MyDateTimeConvertor() );
        settings = jSettings;

a niestandardowy konwerter, którego próbowałem użyć, jest taki:

 public class MyDateTimeConvertor : DateTimeConverterBase
    {
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            return DateTime.Parse(reader.Value.ToString());
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteValue(((DateTime)value).ToString("dd/MM/yyyy hh:mm"));
        }
    }

Anyhelp byłoby mile widziane :)

questionAnswers(2)

yourAnswerToTheQuestion