兼容IE浏览器下对比两个时间大小

IE浏览器下对比两个时间大小

由于IE中new Date 存在兼容问题所以new Date .getTime 无法使用


timeInitialize(){//时间改变时触发
            if(this.startTime && this.endTime){//判断两个时间是否输入
                var dateTime = this.strToDate(this.startTime);
                var timeValue = Date.parse(dateTime);
                var dateTime2 = this.strToDate(this.endTime);
                var timeValue2 = Date.parse(dateTime2);
                if(timeValue>timeValue2){
                    this.$message.error('请输出正确的查询时间')
                    return
                }else{
                    this.initialize()
                }
            }
        },
isEmpty(fData) {
            let _this=this
			if (typeof fData == "function") {
				return false;
			}
			return typeof fData == "undefined" || fData == undefined || fData == null || 
                   fData.length == 0 || fData == 'null' || (fData != false && fData == '');
		},
		isNull : function(fData, replaceData) {
            let _this=this
			return _this.isEmpty(fData) ? replaceData : fData;
		},
strToDate(str) {
            let _this=this
			if (_this.isEmpty(str)) {
				return null;
			}
			var converted = Date.parse(str);
			var myDate = new Date(converted);
			if (isNaN(myDate)) {
				if (str.indexOf(":") != -1) {
					str = str.replace(" ", "-");
					str = str.replace(":", "-");
					str = str.replace(":", "-"); // 第二个时间
					var arys = str.split('-');
					myDate = new Date(arys[0], --arys[1], arys[2], _this.isNull(arys[3], 0), 
                    _this.isNull(arys[4], 0), _this.isNull(arys[5], 0));
				} else {
					var arys = str.split('-');
					myDate = new Date(arys[0], --arys[1], arys[2]);
				}
			}
			return myDate;
		},


发布了2 篇原创文章 · 获赞 2 · 访问量 46

猜你喜欢

转载自blog.csdn.net/qq_45178622/article/details/104059025