• 跨年操作--new Date()


    //时间在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";

    })();

  • 相关阅读:
    iOS 网络编程:socket
    Zsh和Bash,究竟有何不同
    关于微软win10 2004的更新以及wsl2 Ubuntu18.04安装
    C# 委托事件机制 订阅发布
    关于Docker理念和安装,对Visual Studio2019自带生成的DockerFile配置,以及Docker镜像的发布与拉取
    div弹框
    vs分页
    ado显示下拉
    SQL server动态拼接存储过程分页
    退役
  • 原文地址:https://www.cnblogs.com/Super-scarlett/p/8176193.html
Copyright © 2020-2023  润新知