Time interval processing method in JS

Source: Internet
Author: User
Tags date1 idate

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"    &nbsp 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.