Cause
For the date field returned from C #, when the JSON serialization, in the foreground JS display is not a real date, which makes us feel very uncomfortable, we can not for this thing, all date fields into string bar, so, find a JS extension method to achieve this function
Realize
function Changedateformat (jsondate) {
jsondate = Jsondate.replace ("/date (", ""). Replace (")/", "");
if (Jsondate.indexof ("+") > 0) {
jsondate = jsondate.substring (0, Jsondate.indexof ("+"));
}
else if (Jsondate.indexof ("-") > 0) {
jsondate = jsondate.substring (0, Jsondate.indexof ("-"));
}
var date = new Date (parseint (jsondate));
var month = Date.getmonth () + 1 < 10? "0" + (date.getmonth () + 1): Date.getmonth () + 1;
var currentdate = date.getdate () < 10? "0" + date.getdate (): Date.getdate ();
Return Date.getfullyear ()
+ "year"
+ month
+ "month"
+ currentdate
+ "Day"
+ ""
+ Date.gethours ()
+ ":"
+ date.getminutes ();
}
Call: Changedateformat (data[i].arrdate)
Call
$.ajax ({
type: "Get",
texttype: "json",
URL: "/userinfo/getuserwithdraw",
data: {id:id},
Success:function (data) {
var result = Html.replace (reg, function (node, key) {return
{
' money ': data. Money,
' addtime ': Changedateformat (data. addtime),
' cashtime ': Data. Cashtime
}[key];
Tsingdatips.ask ({msg:result, Show_btn:false, title: "Details of the present Application"});//expected to be equal to the time of the application (5th or 20th)
}
);
PS: Returns the JSON time such as/date (1290371638000)/form, how to deal with the YYYY-MM-DD such format
Remove/date
Direct format of 1290371638000
/**
* The format of the time object;
*
/Date.prototype.format = function (format) {/
* * eg:format= "yyyy-mm-dd hh:mm:ss";
* *
var o = {
"m+": This.getmonth () +1,//month
"d+": This.getdate (), //day
"h+": this.gethours () , //hour
"m+": This.getminutes (),//minute
"s+": This.getseconds (),//second
"q+": Math.floor ( This.getmonth () +3)/3),//quarter
"S": This.getmilliseconds ()//millisecond
}
if (/(y+)/.test (format ) {
format = Format.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length));
For (var k in o) {
if (new RegExp ("+ K +")). Test (format) {
format = format.replace (regexp.$1, Regexp.$1.lengt H==1? O[k]: ("+ o[k]"). substr (("+ o[k]). length);
}
return format;
}
How to use:
var testdate = new Date ();
var teststr = Testdate.format ("yyyy mm month DD Day hh hour mm minute ss seconds");
alert (TESTSTR);