时间的基本处理

输出2017-03-05格式

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;
    }
    currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
};
getNowFormatDate();

处理结束时间不小于开始时间

var currentdate;
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;
    }
    currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
};
getNowFormatDate();
$('.start_date_input').val(currentdate);
$('.start_date').datetimepicker({
    format: 'yyyy-mm-dd',
    language: 'zh-CN',
    weekStart: 1,
    todayBtn: 1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 2,
    forceParse: 0,
    minView: "month"
});
$('.end_date_input').val(currentdate);
$('.end_date').datetimepicker({
    format: 'yyyy-mm-dd',
    language: 'zh-CN',
    weekStart: 1,
    todayBtn: 1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 2,
    forceParse: 0,
    minView: "month"
});
$('.date_input').on('change', function() {
    var $this = $(this);
    var thisValue = new Date($this.val()).valueOf(),
        anotherValue = new Date($('.date_input').not(this).val()).valueOf();
    if($this.is('.start_date_input')) {
        if(thisValue > anotherValue) {
            wxcepAlert('开始日期不能大于结束日期');
            $this.val('');
        }
    } else {
        if(thisValue < anotherValue) {
            wxcepAlert('开始日期不能大于结束日期');
            $this.val('');
        }
    }
});

猜你喜欢

转载自www.cnblogs.com/zhihou/p/8939990.html