vue+ele 中两个日期之间大小的比较

原创 motu_1991 随笔 vueJs 318阅读 2017-11-08 16:31:54 举报

1.日期大小比较
var checkEndRaiseTime = (rule, value, callback) => {
if (!value) {
this.checkEndRaiseTime = false;
return callback(new Error('不能为空'));
}
if(this.base_info.term_type == 2){
let finalReturnDate = new Date(this.base_info.final_return_date).getTime(),
publishTime = new Date(this.base_info.publish_time).getTime(),
endRaiseTime = new Date(this.base_info.end_raise_time).getTime();
if(finalReturnDate!="" && endRaiseTime!="" && endRaiseTime >= finalReturnDate){
this.checkEndRaiseTime = false;
return callback(new Error('endRaiseTime时间要小于finalReturnDate'));
}else if(publishTime!="" && endRaiseTime!="" && endRaiseTime < publishTime){
this.checkEndRaiseTime = false;
return callback(new Error('endRaiseTime时间不能小于publishTime'));
}

            }else{  //为项目期限时
                let publishTime = new Date(this.base_info.publish_time).getTime(),
                    endRaiseTime = new Date(this.base_info.end_raise_time).getTime();
                if(publishTime!="" && endRaiseTime!="" && endRaiseTime < publishTime){
                    this.checkEndRaiseTime = false;
                    return callback(new Error('endRaiseTime时间不能小于publishTime'));
                }
            }
            this.checkEndRaiseTime = true;
            return callback();
        }

2.有时候ele得到的日期(Fri Sep 22 2017 00:00:00 GMT+0800 (中国标准时间))不是我们想要的格式 yyyy-MM-dd。可以加一个change=“getSTime”事件处理下####:
在meyhods里定义:
getSTime(val){
let finalReturnDate = new Date(this.base_info.final_return_date).getTime(),
publishTime = new Date(val.split(' ')[0]).getTime();
if(publishTime == finalReturnDate){
this.sameTime = true;
}else{
this.sameTime = false;
}
}

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复