The format type of the data[i].logtime here can be 2015-1-20 10:55:48var time = Timebetween (data[i].logtime); The time here gets the current interval.
var warntemp = ' <span class= "Time" > ' +time+ ' </span> '; //assigns the JSP code to the variable Warntemp var warnstr = [warntemp].join ("); //convert it to JSON format/** * @author administrator * the interval between the current time of the alert and the minimum in minutes * @param LogTime */function Timebetween (logtime) {//var st = logtime.split (" "); Var dt = date.parse (new date (Date.parse (logtime))) //converts the date entered into microseconds (1 per thousand seconds) var date1 = new Date (); //gets the current time in the format of the microsecond type var idate = date1.gettime ()-dt; //two microsecond format time subtraction Var itime = returntime (iDate); //processing time in microsecond format return itime;} /** * @author Administrator * @param days * here is defined as the input of a subtle level (s1 per thousand) data come in, processing judgment * @returns {string} */function returntime (itime) { var idate = itime/1000; if (iDate<60) { return "within 1 minutes"; } Idate = idate/60; if (idate<60) { idate = parseint (iDate) +1; //For example 26.5, it needs to be expressed in 27 minutes return idate+ "in minutes"; } idate = idate/60; if (idate<24) { idate = parseint (iDate) +1; return idate + "SmallIn-time "; } idate = idate/24; //There is no further processing, directly according to 30 days one months to divide if (idate<30) { idate = parseint (iDate) +1; return "within 1 months"; } iDate = iDate/30; if (idate<12) { idate = parseint (iDate) +1; return idate+ "within a month"; } iDate = iDate/12; &nbSp; if (iDate>=1) { idate = parseint (iDate) +1; return idate+ "Year"; } else{ return "within 1 days"; //execute "within 1 days"   when wrong;}}
$ ("#kpi_warning"). HTML (WARNSTR); Insert the code directly under the <li> tag with id kpi_warning <li id= "kpi_warning" ></li>//<li> tab There will be a processing time interval.
This article is from the "JS time interval Processing" blog, please be sure to keep this source http://liqi123.blog.51cto.com/6406280/1606042
Time interval processing method in JS