zoukankan      html  css  js  c++  java
  • JS关于时间的计算

    用javascript返回两个时间差,精确到秒:

     
     

    Date.diff = function(a,b)
    {
            if(a instanceof Date && b.instanceof Date)
            {
                    return Math.round((a.getTime() - b.getTime()) / 1000);
            }
            else
            {
                    throw new Error("Argument Exception");
            }
    }

     

    参考:(new Date(Date String) - new Date(OldDate String) )/1000

     

    时间格式转换为毫秒数:

    EX:Date.parse("01/01/2011 10:10:10")

    EX:

    var timeGet = $("#J_date_1").attr("value");

    var _timeGet = timeGet.split("-");

    var timeGetFix = Date.parse(_timeGet[0] + "/" + _timeGet[1] + "/" + _timeGet[2] + " " + $("#gettime").attr("value"));

    var timeRet = $("#J_date_2").attr("value");

    var _timeRet = timeGet.split("-");

    var timeRetFix = Date.parse(_timeRet[0] + "/" + _timeRet[1] + "/" + _timeRet[2] + " " + $("#rettime").attr("value")) + 86400000;

     

    if ((timeRetFix - timeGetFix) / 3600000 < 24)

    {

        $(".step1-box .ts-box").show();

    }

    else

    {

        $(".step1-box .ts-box").hide();

    }

     
  • 相关阅读:
    797. 所有可能的路径
    1286. 字母组合迭代器
    216. 组合总和 III
    77. 组合
    784. 字母大小写全排列
    90. 子集 II
    78. 子集
    47. 全排列 II
    46. 全排列
    40. 组合总和 II
  • 原文地址:https://www.cnblogs.com/mixzo/p/4213661.html
Copyright © 2011-2022 走看看