1

I cerated odata webservice in C# the JSON response return datetime field formatted like :

"updated": "2017-01-25T01:40:04",

how can I format it like "2017-01-25 01:40" ?

CDominik
  • 115
  • 1
  • 10

1 Answers1

2

I assume you are using Newtonsoft.Json and that you want the format to be global (apply the format to every date)

Put this in the Application_Start method:

HttpConfiguration config = GlobalConfiguration.Configuration;
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
     new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm" });

More info in this possible duplicate question

Community
  • 1
  • 1
Dávid Molnár
  • 10,673
  • 7
  • 30
  • 55
  • does not work, maybe because the type edm.datetime does not match with IsoDateTime. I tried also using jsonConverter as attribute ... nothing – CDominik May 15 '17 at 14:07
  • Then please add some details about your data types to your question. I assumed you are using System.DateTime. – Dávid Molnár May 15 '17 at 18:38