zoukankan      html  css  js  c++  java
  • Jquery计算时间戳之间的差值,可返回年,月,日,小时等

    /**
     * 计算时间戳之间的差值
     * @param startTime 开始时间戳
     * @param endTime 结束时间戳
     * @param type 返回指定类型差值(year, month, day, hour, minute, second)
     */
    function DateDiff(startTime, endTime, type) {
        var timeDiff = endTime - startTime
        switch (type) {
            case "year":
                return Math.floor(timeDiff / 86400 / 365);
                break;
            case "month":
                return Math.floor(timeDiff / 86400 / 30);
                break;
            case "day":
                return Math.floor(timeDiff / 86400);
                break;
            case "hour":
                return Math.floor(timeDiff / 3600);
                break;
            case "minute":
                return Math.floor(timeDiff / 60);
                break;
            case "second":
                return timeDiff % 60;
                break;
        }
  • 相关阅读:
    js字符串空格和换行
    python resources
    -eous
    英语资源网站
    -iatry 没病走两步
    book corpus
    epub converters
    brainstorm detain
    craftsman
    parachute
  • 原文地址:https://www.cnblogs.com/firstcsharp/p/10293273.html
Copyright © 2011-2022 走看看