Home>

cause

For date fields returned from c#,After json serialization,The real date is not displayed in the foreground js,It makes us feel bad,We can't do this.Turn all date fields into strings, so find a js extension method,To achieve this function

achieve

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, 10));
  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)

transfer

$.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 withdrawal application"});//Estimated payment time is equal to the time after application (5th or 20th)
      }
    });

ps:The returned json time is in the form of/date (1290371638000) /, how to handle it into a format such as yyyy-mm-dd

Remove/date

Format 1290371638000 directly

/**
* Formatting of time objects;
* /
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.length == 1?o [k]:("00" + o [k]). substr (("" + o [k]). length));
  }
  }
 return format;
}

Instructions:

var testdate=new date ();
var teststr=testdate.format ("yyyy mm mm dd day hh hour mm minute ss second");
alert (teststr);
  • Previous Jquery plugin pagination to achieve no refresh ajax pagination
  • Next Summary of the causes of session invalidation and how to solve it