简体   繁体   中英

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)/"}

But what I want is to return the same value using an attribute to the dateTime parameter instead.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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