杰森日期时间问题
Possible Duplicate:
how to force netwtonsoft json serializer to serialize datetime property to string?
我正在使用Newtonsoft.Json将我的对象转换为JSON文件.
但是我在对象日期时间字段中将DateTime
设置为"7/30/2012 8:29:12 PM"
,但是在JSON文件中却遇到了问题.我正在使用以下格式的DateTime
字段:
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)\/"
.
我需要以与对象相同的格式获取DateTime
.是否有可能?我该怎么做才能获得相同的格式?
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?
我得到了如下解决方案.
I got the solution as follow.
JsonConvert.SerializeObject(this, Formatting.None, new IsoDateTimeConverter() {
DateTimeFormat = "yyyy-MM-dd hh:mm:ss"
});
这是答案: