简体   繁体   English

使用Json ATTRIBUTE序列化日期时间,使其在C#中看起来像/ Date(1486516302715)

[英]using Json ATTRIBUTE to serialize datetime to look like /Date(1486516302715) in C#

class className 
{ 
    Datetime dateTime {get; set;} 
}
className object = new className();

When I use Json(object) this returns the dateTime field in this format : {"dateTime":"/Date(1486516302715)/"} 当我使用Json(object)时,它以以下格式返回dateTime字段:{“ dateTime”:“ / Date(1486516302715)/”}

But what I want is to return the same value using an attribute to the dateTime parameter instead. 但是我想要的是使用dateTime参数的属性返回相同的值。

Something like : 就像是 :

[JsonConverter(typeof(JavaScriptDateTimeConverter))]
Datetime dateTime {get; set;}

Only the JavaScriptDateTimeConverter is not the one which gives me the date in the right format. 只有JavaScriptDateTimeConverter不能为我提供正确格式的日期。

在javascript中,您可以使用新的Date方法。

new Date(parseInt(date.substr(6))); // date= "/Date(1486516302715)/"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM