zoukankan      html  css  js  c++  java
  • 跨年操作--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";

    })();

  • 相关阅读:
    Oracle 11g 在本机上安装PLSQL DEveloper
    Oracle 11g 启动与关闭服务的脚本
    Oracle 11g 安装过程图解
    linux下vi命令大全
    accuracy、precision、recall、true positives, true negatives, false positives 和 false negatives
    // 40、用1、2、2、3、4、5这六个数字,写一个main函数,打印出所有不同的排列, // 如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连.
    阿里巴巴第二道(研发类) 笔试题1,原题大致描述有一大批数据,百万级别的。数据项内容是:用户ID、科
    621. Task Scheduler
    625. Minimum Factorization
    623. Add One Row to Tree
  • 原文地址:https://www.cnblogs.com/Super-scarlett/p/8176193.html
Copyright © 2011-2022 走看看