zoukankan      html  css  js  c++  java
  • jquery 计算两个日期之间的相差天数 ,获取当前时间

    最简单的方法使用DateDiff(),判断在两个日期之间存在的指定时间间隔的数目,但是Safari不识别

    $(function(){
        var beginTime="2015-08-20";
        var endTime="2015-12-11";
        var days=DateDiff(beginTime,endTime) 
        alert(days)  
    })
    
    第二种方法:
    var beginTime="2015-08-20";
    var endTime="2015-12-11";
    var aDate, oDate1, oDate2, days; 
    aDate = beginTime.split("-"); 
    oDate1 = new Date(aDate[0], aDate[1], aDate[2]); 
    aDate = endTime.split("-"); 
    oDate2 = new Date(aDate[0] , aDate[1] , aDate[2]); 
    days = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24);

     获取当前时间

    function addZero(obj) {
            if (obj < 10) return "0" + obj; else return obj
        }
        var currentDate = function () {
            var mydate = new Date();
            var curr_year = mydate.getFullYear();
            var curr_month = mydate.getMonth() + 1;
            var curr_day = mydate.getDate();
            var curr_H = mydate.getHours();
            var curr_M = mydate.getMinutes();
            var curr_S = mydate.getSeconds();
            var monthDate = curr_year + "-" + addZero(curr_month) + "-" + addZero(curr_day) + " " +addZero(curr_H)+":"+addZero(curr_M)+":"+addZero(curr_S);
            return monthDate;
        }
        $("#dataTime").val(currentDate());
  • 相关阅读:
    Jdbc增删改查的相关操作(Oracle 数据库环境)
    java
    今日随笔
    爬虫之链家网
    爬虫之搜狗
    【题解】「UVA1149」装箱 Bin Packing
    【题解】「SP34013」SEUG
    【题解】「SP867」 CUBES
    【题解】NOI 系列题解总集
    APIO2019简要题解
  • 原文地址:https://www.cnblogs.com/cjqa/p/4745200.html
Copyright © 2011-2022 走看看