首页 > 代码库 > js 获取时间差
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=http://www.mamicode.com/time/minute;
break;
case "hour":
newValue=http://www.mamicode.com/time/hour;
break;
case "day":
newValue=http://www.mamicode.com/time/day;
break;
case "halfamonth":
newValue=http://www.mamicode.com/time/halfamonth;
break;
case "month":
newValue=http://www.mamicode.com/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));
js 获取时间差