Dates without time in ASP.NET Web API's JSON output

Is there a simple way to configure JSON.NET so that some DateTime fields will be formatted without time?

Example: { firstName: 'John', lastName : 'Doe', birthday: '1965-09-23' }

Answers


If you need this to only affect a particular field, create a converter type first:

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

and then add this attribute to whatever fields/properties you want this for:

[JsonConverter(typeof(OnlyDateConverter))]

Need Your Help

groovy parse xml into pojo

xml groovy pojo

i need to get this url (http://localhost:8983/solr/select/?q=treen&omitHeader=true) and get the response as xml, and for each record, parse it to a class and then create a final map with all the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.