码迷,mamicode.com
首页 > Web开发 > 详细

js 获取时间差

时间:2014-10-15 18:12:01      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   sp   2014   on   cti   log   代码   

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

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));

 

js 获取时间差

标签:io   ar   for   sp   2014   on   cti   log   代码   

原文地址:http://www.cnblogs.com/shen119/p/4026656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!