日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

跨年操作--new Date()

發布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 跨年操作--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";

})();

?

轉載于:https://www.cnblogs.com/Super-scarlett/p/8176193.html

總結

以上是生活随笔為你收集整理的跨年操作--new Date()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。