Json Datetime issue [duplicate]

心不动则不痛 提交于 2019-12-10 00:52:37

问题


Possible Duplicate:
how to force netwtonsoft json serializer to serialize datetime property to string?

I am using Newtonsoft.Json to convert my object in to JSON file. But I am having issue with the DateTime, in my object datetime field is set as "7/30/2012 8:29:12 PM" but in JSON file. I am getting DateTime field in this format:

"\/Date(1343660352227+0530)\/".

I need to get the DateTime in the same format as that of the object. Is it possible? What should I do in order to get the same format?


回答1:


I got the solution as follow.

JsonConvert.SerializeObject(this, Formatting.None, new IsoDateTimeConverter() {
    DateTimeFormat = "yyyy-MM-dd hh:mm:ss"
});

Here is the answer:

how to force netwtonsoft json serializer to serialize datetime property to string?



来源:https://stackoverflow.com/questions/11757757/json-datetime-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!