DATE hours of time difference function, the statistical difference between the two time

//计算时间差函数
            difference() {
                if (this.formData.startTime!==''&&this.formData.endTime!==''){
                    let start = this.formData.startTime;
                    let end = this.formData.endTime;
                    console.log(start,end,88888)
                    let dateBegin = new Date(start.substring(0,10));
                    let dateEnd = new Date(end.substring(0,10));
                    let dateDiff = dateEnd.getTime() - dateBegin.getTime();//时间差的毫秒数
                    let dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)) +1;//计算出相差天数

                    if (end.substring(11,13) < this.flyTime ){   //this.timeNode从字典表里面取,飞机起飞时间15时
                        dayDiff = dayDiff -0.5;
                    }else  if (end.substring(11,13) == this.flyTime ){
                        if (end.substring(14,15) ==0 && end.substring(15,16) ==0 ){
                            dayDiff = dayDiff- 0.5;
                        }
                    }
                    if (start.substring(11,13) > this.flyTime){
                        dayDiff = dayDiff- 0.5;
                    }else if (start.substring(11,13) == this.flyTime){
                        if (start.substring(14,15) >0 ){
                            dayDiff = dayDiff- 0.5;
                        }else  if (start.substring(15,16) >0 ){
                            dayDiff = dayDiff- 0.5;
                        }
                    }
                    this.formData.businessTripDays = dayDiff;
                }else {
                    this.formData.businessTripDays  = 0;
                }
            },
Published 19 original articles · won praise 1 · views 325

Guess you like

Origin blog.csdn.net/qq_41444226/article/details/104231295