c# - Modifiy JSON Date time object format -
c# - Modifiy JSON Date time object format -
hi writing json webservice returns datetime.
it returning date time in epoch format. possible modify json date format returns.
code snippet
[servicecontract] public interface itmappservices { [operationcontract] [webget(uritemplate = "/test", requestformat = webmessageformat.json, responseformat = webmessageformat.json)] datetime getdata(); }
actual implementaiton
public class tmappservices : itmappservices { public datetime getdata() { homecoming datetime.now; } }
i returning datetime.now in c#
output in epoch format :
"/date(1413399311687+0300)/"
i want output in same format returned c# or if datetime sql
it looks you're writing wcf service. default, wcf uses datacontractjsonserializer
json serialization - uses format.
you should consider either replacing json.net - or preferably, writing service asp.net webapi instead - uses json.net.
json.net (by default) utilize iso-8601 serialization format. preferred format sending dates on wire, in json. example, "2014-10-15t21:54:00-07:00"
.
you should not utilize dd mm yyyy
format, json intended machine readable. if machine mm dd yyyy
civilization attempts read string, misinterpret value. example, "1/2/2014" can read either jan 2nd, or feb 1st.
as aside - should consider using datetimeoffset
type in .net instead of datetime
.
c# json datetime
Comments
Post a Comment