js 获取时间差

写这片博客 ,下面代码虽然简单,但却很实用...默默留下来...

var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var halfamonth = day * 15;
var month = day * 30;
function Diff(type,dateNew,dateOld){
    var time=dateNew.getTime()-dateOld.getTime();
    if(time<0)
        return;
    var newValue="";
   switch (type){
       case "minute":
           newValue=time/minute;
           break;
       case "hour":
           newValue=time/hour;
           break;
       case "day":
           newValue=time/day;
           break;
       case "halfamonth":
           newValue=time/halfamonth;
           break;
       case "month":
           newValue=time/month;
           break;
   }
    return newValue;
}
//console.log(unique(o))
    var s="a,b,b";
    var t= s.split(",");
    console.log(t);
    console.log(contains("d",t) );
   var datebefore=new Date();
    var dateafter=new Date();
    var t=dateafter-datebefore;
    // alert(t+"s");
    var  s="2014-10-13 15:09:18";
    var dateOld=new Date(s);
    var dateNew=new Date("2014-10-15 15:09:18")    ;
    console.log(Diff("day",dateNew,dateOld));

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。