Este artículo describe el método de JavaScript para comparar si el tiempo actual está dentro de un período de tiempo especificado. Compártelo para su referencia, como sigue:
Function Checktime (STEME, Etime) {// Start Time var Arrrs = STEME.Split ("-"); var starttime = nueva fecha (arrs [0], arrrs [1], arrrs [2]); var startTimes = starttime.gettime (); // Tiempo de finalización var arr = etime.split ("-"); var tiempo final = nueva fecha (arre [0], arr [1], arr [2]); var endTimes = endtime.gettime (); // Tiempo actual var thisDate = new Date (); var thisDates = thisDate.getblyear () + "-0" + (thisDate.getMonth () + 1) + "-" + thisDate.getDate (); var arrn = thisDates.split ("-"); var ahora tiempo = nueva fecha (arrn [0], arrn [1], arrn [2]); var nowTimes = NowTime.GetTime (); if (nowTimes <startTimes || ahoraTimes> endTimes) {return false; } return true;} // Uso: var TimeBool = checktime ('2016-8-1', '2016-8-10'); // NOTA: Las fechas están separadas por "-" if (TimeBool == true) {document.Write ('La fecha actual está dentro del período de tiempo especificado');} else {document.write ('La fecha actual no está dentro del período de tiempo especificado');}PD: Los amigos interesados en las operaciones de hora y fecha de JavaScript también pueden referirse a las herramientas en línea de este sitio:
Herramienta de conversión de la marca de tiempo UNIX:
http://tools.vevb.com/code/unixtime
Consulta de tiempo en línea en todo el mundo:
http://tools.vevb.com/zhuanhuanqi/worldtime
Calendario perpetuo en línea:
http://tools.vevb.com/bianmin/wannianli
Calendario perpetuo 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", "Resumen del algoritmo y habilidades de traversal de JavaScript" y "Resumen del uso de la operación matemática de JavaScript"
Espero que este artículo sea útil para la programación de JavaScript de todos.