JS限制某个时间段不能操作代码

timezeo(num){
  return num < 10 ? '0' + num : num
},

dateFormat(date,time=''){
  var year    = new Date(date).getFullYear();
  var month	  = new Date(date).getMonth();
  var day     = new Date(date).getDate();
  var hours 	= new Date(date).getHours();
  var minutes = new Date(date).getMinutes();
  var seconds = new Date(date).getSeconds();
  var result = `${year}-${this.timezeo(month)}-${this.timezeo(day)}`	
  return time != '' ? `${result} ${time}` : `${result}     
  ${this.timezeo(hours)}:${this.timezeo(minutes)}:${this.timezeo(seconds)}`
},

function opt(){
    const date = new Date();
    var startTime = new Date();
    var endTime = new Date(date.setDate(date.getDate()+1));
    startTime   = this.dateFormat(startTime,'23:00:00')
    endTime 	= this.dateFormat(endTime,'08:00:00')
    var curtime = this.dateFormat(new Date(),'')			
    if(curtime >= startTime && curtime <= endTime){
      uni.showModal({title:"温馨提示",content:"系统维护中,晚上23点到次日早上8点。",showCancel:false})
      return false;
    }

    //过了时间段继续执行.....
}

限制了晚上23点到第二天早上8点不能操作。

你可能感兴趣的:(javascript,开发语言,ecmascript)