0

I have a generic Api in Rest service which get a datatable that was filled from sql table and return it as Json using stream. part of the fields in my table includes date in yyyy-MM-dd HH:mm:ss format,all the values that has a valid sql date,return with Epoch date time representation. how can I solve it? see code:

System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string t = serializer.Serialize(dataTableFromSQL);
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(t));
return ms;
user1666620
  • 4,800
  • 18
  • 27
avi dvir
  • 1
  • 2
  • JavaScriptSerializer, don't use it. Use another serializer. http://stackoverflow.com/questions/17069460/javascriptserializer-utc-datetime-issues – Tewr May 19 '16 at 11:50
  • "Simple".. not really. depends on why and how you are displaying the data. you have tagged API and REST. Where are you "displaying" this? on a webpage? Then you should stay as standard as possible server-side, keep your dates in UTC. There are several methods and libraries for formatting dates once on the client side. dont forget to account for time zone. date.js is one library which is nice for formatting dates. you could detect dates using a regex perhaps, if you don't know the names of date properties beforehand. – Tewr May 19 '16 at 15:09

0 Answers0