この記事では、現在の時間が指定された期間内であるかどうかを比較するJavaScriptの方法について説明します。次のように、参照のために共有してください。
function checktime(stime、etime){//開始時間var arrrs = stime.split( " - "); var starttime = new Date(arrs [0]、arrrs [1]、arrrs [2]); var starttimes = starttime.getTime(); //終了時間var arr = etime.split( " - "); var endtime = new Date(arre [0]、arr [1]、arr [2]); var endtimes = endtime.getTime(); //現在の時間var thisdate = new date(); var thisdates = thisdate.get.fullyear() + "-0" +(thisdate.getMonth() + 1) + " - " + thisdate.getDate(); var arrn = thisdates.split( " - "); var nowtime = new Date(arrn [0]、arrn [1]、arrn [2]); var nowtimes = nowtime.getTime(); if(nowtimes <starttimes || nowtimes> endtimes){return false; } return true;} // usage:var timebool = checktime( '2016-8-1'、 '2016-8-10'); //注:日付は " - "で区切られています。PS:JavaScriptの時間と日付の操作に興味がある友人は、このサイトのオンラインツールを参照することもできます。
UNIXタイムスタンプ変換ツール:
http://tools.vevb.com/code/unixtime
世界中のオンライン時間調査:
http://tools.vevb.com/zhuanhuanqi/worldtime
オンライン永久カレンダー:
http://tools.vevb.com/bianmin/wannianli
Web永久カレンダー:
http://tools.vevb.com/bianmin/webwannianli
For more information about JavaScript, please check this site's special topics: "Summary of JavaScript Time and Date Operation Skills", "Summary of JavaScript Switching Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills", 「JavaScriptトラバーサルアルゴリズムとスキルの概要」および「JavaScript数学的操作の使用の概要」
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。