4

I am trying to apply a custom datetime format to an array of datetime values. I know you can use IsoDateTimeConverter to accomplish this for single values e.g.

class CustomDateTimeConverter : IsoDateTimeConverter
{
    public CustomDateTimeConverter()
    {
        base.DateTimeFormat = "yyyy-MM-dd";
    }
}

class ReturnObjectA 
{
    [JsonConverter(typeof(CustomDateTimeConverter))]
    public DateTime ReturnDate { get; set;}
}

But how do apply the same thing to an array of datetimes? e.g. The following does not work.

class ReturnObjectA 
{
    [JsonConverter(typeof(CustomDateTimeConverter))]
    public DateTime[] ReturnDate { get; set;}
}

1 Answer 1

4

JsonProperty is what you're looking for:

class ReturnObjectA
{
    [JsonProperty(ItemConverterType = typeof(CustomDateTimeConverter))]
    public DateTime[] ReturnDate { get; set; }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.