JS Display friendly time format "Just, a few seconds ago, hours, days ago (within 3 days) time format"

Source: Internet
Author: User

/** * milliseconds conversion friendly display format * output format: 21 hours 28 minutes 15 seconds * @param {[type]} time [description] * @return {[type]} [description]*/functionTimetodate (time) {//gets the current time stamp    varCurrentTime = parseint (NewDate (). GetTime ()/1000);varDifftime = currenttime-Time ; varSecond = 0; varminute = 0; varHour = 0; if(NULL! = Difftime && ""! =difftime) {        if(Difftime > && difftime < 60 * 60) {Difftime= parseint (difftime/60.0) + "minutes" + parseint ((parsefloat (difftime/60.0)-parseint (difftime/60.0)) * 60) + "seconds"; }        Else if(Difftime >= * && Difftime < 60 * 60 * 24) {Difftime= parseint (difftime/3600.0) + "Hour" + parseint (parsefloat (difftime/3600.0)-parseint (Difftime/3600.0)) * 60) + "minutes" +parseint ((parsefloat (parsefloat (difftime/3600.0)-parseint (difftime/3600.0)) * 60)-parseint ((parsefloat (Difftime/3600.0)-parseint (difftime/3600.0)) * 60)) * 60) + "seconds"; }        Else {            //more than 1 days            varDate =NewDate (parseint (time) * 1000); Difftime= Date.getfullyear () + "/" + (Date.getmonth () +1) + "/" +date.getdate (); //difftime = parseint (difftime) + "second";        }    }    returnDifftime;}
/** * milliseconds conversion friendly display format * output format: 21 hours ago * @param {[type]} time [description] * @return {[type]} [description]*/functionDatestr (date) {//Get JS timestamp    varTime=NewDate (). GetTime (); //remove three bits after JS timestamp, consistent with PHP timestampTime=parseint ((time-date*1000)/1000);//Store Conversion Values    vars; if(TIME&LT;60*10) {//within 10 minutes        returnJust; }Else if((time<60*60) && (time>=60*10)){        //more than 10 minutes less than 1 hourss = Math.floor (TIME/60);returnS+ "Minutes Ago"; }Else if((time<60*60*24) && (time>=60*60)){         //more than 1 hours less than 24 hourss = Math.floor (time/60/60); returnS+ "Hours Ago"; }Else if((time<60*60*24*3) && (time>=60*60*24)){         //less than 3 days in excess of 1 dayss = Math.floor (TIME/60/60/24);returnS+ "Days Ago"; }Else{         //more than 3 days        varDate=NewDate (parseint (date) * 1000); returnDate.getfullyear () + "/" + (Date.getmonth () +1) + "/" +date.getdate (); }}

JS Display friendly time format "Just, a few seconds ago, hours, days ago (within 3 days) time format"

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.