//时间在2017/12/31 17:00 --- 2018/1/1 06:00区间,提示用户无法操作公告。

//time.js

(function(){

var date = new Date();

//当前年份

       var year = date.getFullYear();

       //当前月份

       var month = date.getMonth()+1;

       //当前日

       var day = date.getDate();

       //当前小时

       var hour = date.getHours();

       //当前分钟

       var minute = date.getMinutes();

       //当前秒

       var second = date.getSeconds();

       //当前日期时间

       var timedate = date.toLocaleString(); 

       

       var config ={

       starttime : "2017-12-31_17:00",//开始时间

       endtime:"2018-01-1_06:00"       //结束时间

       

       }

       var start = config.starttime.split("_"); 

       var end = config.endtime.split("_");

       

       var yearFlag = start[0].split("-")[0];

       var nextYear = end[0].split("-")[0];

       

       var monthFlag = start[0].split("-")[1];

       var nextMonth = end[0].split("-")[1];

       

       var dayFlag = start[0].split("-")[2];

       var nextDay = end[0].split("-")[2];

       

       var hourFlag =  start[1].split(":")[0];

       var nextHour = end[1].split(":")[0];

       

       var minuteFlag =  start[1].split(":")[1];

       var nextMinute = end[1].split(":")[1];

       

       console.log('date',date);

       console.log('year',typeof(year));

       console.log('month',month);

       console.log('day',day);

       console.log('hour',typeof(hour));

       console.log('minute',minute);

       console.log('second',second);

       console.log('当前日期时间',timedate);

       

       //判断当前时间是否在2017/12/31 17:00 --- 2018/1/1 06:00区间

       if(year != yearFlag){ //2018年

       if(month != nextMonth){

       return;

       }else{ //等于1月

       if(day != nextDay){

       return;

       }else{ //等于1日

       if(hour>=nextHour){

       return;

       }

       }

       }

       }else{ //2017年

       if(month < monthFlag || month > nextMonth){

       return;

       }else{ //等于12月

       if(day < dayFlag || day > nextDay){ 

       return;

       }else{ //等于31日

       if(hour < hourFlag || hour>nextHour){

       return;

       }else{ //大于等于17点

       if(minute < minuteFlag || minute > nextMinute){

       return;

       }

       }

       }

       }

       

       }

       

       location.href="https://xxx/error.html";

})();