js 时间操作

来源:互联网 发布:付费软件怎么收费 编辑:程序博客网 时间:2024/05/29 15:30

jq获取时间

//获取当前时间,格式YYYY-MM-DD    function getNowFormatDate() {        var date = new Date();        var seperator1 = "-";        var year = date.getFullYear();        var month = date.getMonth() + 1;        var strDate = date.getDate();        if (month >= 1 && month <= 9) {            month = "0" + month;        }        if (strDate >= 0 && strDate <= 9) {            strDate = "0" + strDate;        }        var currentdate = year + seperator1 + month + seperator1 + strDate;        return currentdate;    }


jq时间比较,先转换成日期,然后用毫秒数进行比较

function tab(date1,date2){    var oDate1 = new Date(date1);    var oDate2 = new Date(date2);    if(oDate1.getTime() > oDate2.getTime()){        console.log('第一个大');    } else {        console.log('第二个大');    }}tab('2015-10-10','2015-10-11');




0 0
原创粉丝点击