$.fn.extend ({/** * The timestamp is displayed as "Not long ago, just, n minutes before, n hours ago, n days ago, n weeks ago, n months ago, n years n months n days" of processing * *. * * $ (' 1517451000000 '). Commontimestamp (); February 01, 2018 * * $ (new Date (' 2018-02-01 15:10:00 '). GetTime ()). Commontimestamp (); 1 minutes ago*/ "Commontimestamp": Function () {//13-bit full complement varArrtimestamp = ( This. selector | | $( This)[0] +"'). Split ("'), Zero= function (value) {//0 Method of numerical complement if(Value <Ten) { return '0'+value; } returnvalue; }, Arrtime={minute:60000,//*,Hour3600000,//* * ,Day86400000,//* * * ,Week604800000,//* 7,Halfamonth:1296000000,//* * * ,Month2592000000,//* * * ,NowNewDate (). GetTime ()}; for(varStart =0; Start < -; start++) { if(!Arrtimestamp[start]) {Arrtimestamp[start]='0'; }} Arrtimestamp= Arrtimestamp.join ("') *1; Arrtime.diffvalue=NewDate (). GetTime ()-Arrtimestamp; //If the local time is less than the variable time if(Arrtime.diffvalue <0) { return 'Not long ago'; } //magnitude of variance time calculation varArrtimediff ={MonthC:arrTime.diffValue/Arrtime.month, WeekC:arrTime.diffValue/Arrtime.week, DayC:arrTime.diffValue/Arrtime.day, HourC:arrTime.diffValue/Arrtime.hour, MinC:arrTime.diffValue/Arrtime.minute,}; //Use if(Arrtimediff.monthc > A) { //more than 1 years, direct display month Day return(function () {varDate =NewDate (Arrtimestamp); returnDate.getfullyear () +'years'+ zero (date.getmonth () +1) +'Month'+ zero (date.getdate ()) +'Day'; })(); } Else if(ARRTIMEDIFF.MONTHC >=1) { returnparseint (ARRTIMEDIFF.MONTHC) +"months ago"; } Else if(ARRTIMEDIFF.WEEKC >=1) { returnparseint (ARRTIMEDIFF.WEEKC) +"weeks ago"; } Else if(Arrtimediff.dayc >=1) { returnparseint (ARRTIMEDIFF.DAYC) +"days ago"; } Else if(Arrtimediff.hourc >=1) { returnparseint (ARRTIMEDIFF.HOURC) +"hours ago"; } Else if(Arrtimediff.minc >=1) { returnparseint (Arrtimediff.minc) +"minutes ago"; } return 'just'; }, /** * The timestamp is displayed as "Today 10:10, today 15:10, yesterday 10:10, yesterday 15:10, 10:10, 15:10" Treatment * *. * * $ (' 1517451000000 '). Specifictimestamp (); This Morning 10:10 * * $ (new Date (' 2018-02-01 15:10:00 '). GetTime ()). Specifictimestamp (); 15:10 this afternoon .*/ "Specifictimestamp": Function () {varArrtimestamp = This. selector | | $( This)[0] -0, Partime=NewDate (arrtimestamp), Diffday= parseint ((NewDate (). GetTime ()-Arrtimestamp)/( +* -* -* -)); //Use return((Diffday >=1&& Diffday <=2) ?"Yesterday": (Diffday>=0&& Diffday <=1) ?"Today":"") +( (partime.gethours ()/ A>1?"Afternoon":"Morning") +partime.gethours ()+":"+partime.getminutes ()); } });
JS JQ plugin Display Chinese timestamp just n minutes ago N hours ago this morning afternoon