Datetime in Javascript needs to use new date (318326400000). The JSON time format returned by Asp.net MVC is/date (318326400000 )/
The date type of JSON data consumed by the jquery. Ajax () function can be added through jquery. Ajax. datafilter in jquery 1.2.6 or later versions.
Step 1: Use the datafilter function of jquery. Ajax () to pre-process the Asp.net datetime object to a local JavaScript Object.
$. Ajax ({
Type: "Post ",
Datatype: "JSON", // data format: JSON
URL: '/myproject/searchmailinfojson', // target address
Data: "page =" + pageindx + buildwhere (),
Beforesend: function () {$ ("# divload"). Show (); $ ("# pagination"). Hide () ;}, // before sending data
Complete: function () {$ ("# divload"). Hide (); $ ("# pagination"). Show () ;}, // The data has been received
Datafilter: function (data, type ){
Return data. Replace (/"\\\/ (date \ ([0-9-] + \) \\\/"/GI, 'new $1 ');
},
Success: function (JSON ){
$ ("# List-Table TR: GT (0)"). Remove ();
$. Each (JSON, function (I, item ){
If (item ["sendtime"] = NULL ){
Item ["sendtime"] = "";
}
VaR TRS = "";
TRS + = "<tr style = 'font-weight: '> <TD align = 'center'>" + item ["emailsubject"];
TRS + = "</TD> <TD align = 'center' style = 'word-wrap: Break-word; Word-break: Break-all; '> ";
TRS + = item ["messageto"] + "</TD> <TD>" + item ["messagefrom"] + "</TD> ";
TRS + = "<TD align = 'left'>" + item ["emailcc"] + "</TD> <TD align = 'center'>" + item ["mailtype "] +" </TD> ";
TRS + = "<TD align = 'center'>" + dateformat (item ["arriveddatetime"], "yyyy-mm-dd hh: mm: SS ") + "</TD> ";
TRS + = "<TD align = 'center'>" + item ["status"] + "</TD> ";
TRS + = "<TD align = 'center'>" + dateformat (item ["sendtime"], "yyyy-mm-dd hh: mm: SS ") + "</TD> ";
TRS + = "<TD> <a href = 'javascript: showpopwin ('effect preview', 'sendmailpreview? Sysid = "+ item [" systemid "] +" & mailid = "+ item [" ID "] +" ', 600,600, null, true, true);> preview </a> </TD> <tr> ";
Tbody + = TRS;
});
$ ("# List-table"). append (tbody );
$ ("# List-Table TR: GT (0)"). Hover (function (){
$ (This). addclass ('mouseover ');
}, Function (){
$ (This). removeclass ('mouseover ');
});
}
});
Step 2 process the string representation of the date in Javascript, similar to. Net datetime. tostring (). This can use another JavaScript time format library, see the http://blog.stevenlevithan.com/archives/date-time-format
Http://www.overset.com/2008/07/18/simple-jquery-json-aspnet-webservice-datetime-support/