Format DateTime for both XML and JSON response

I have a dotnet core API in which i have a model that looks something like this:

class A {   public DateTime time {get; set;} } 

I would like to keep the property time as a DateTime, but when sending the response I want to format it as a string with the following format: yyyy-MM-dd.

My problem is that I need to return in either XML or JSON, depending og the header in my request.

So my question is; Without changing the type, how do I make the API return the property time in the format i want for both XML and JSON?

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.