zoukankan      html  css  js  c++  java
  • 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));

  • 相关阅读:
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
    今日总结
    Interesting Finds: 2010 02.08 ~ 02.13
  • 原文地址:https://www.cnblogs.com/shen119/p/4026656.html
Copyright © 2011-2022 走看看