簡體   English   中英

如何確保將計時器設置為每天4點半,所以我不必在Javascript中提及某個日期?

[英]How can I make sure the timer is set to half 4 every day, so I don't have to mention a certain date in Javascript?

如何確保將計時器設置為每天4點半,所以我不必在Javascript中提及某個日期? 還有如何以div或p而不是形式顯示輸出。

 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>jQuery Countdown</title> </head> <body> <script language="javascript" type="text/javascript"> function getTime() { now = new Date(); orderBy = new Date("May 17 2016 16:30:00"); //days = (orderBy - now) / 1000 / 60 / 60 / 24; daysRound = Math.floor(days); hours = (orderBy - now) / 1000 / 60 / 60 - (24 * daysRound); hoursRound = Math.floor(hours); minutes = (orderBy - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound); minutesRound = Math.floor(minutes); seconds = (orderBy - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound); secondsRound = Math.round(seconds); sec = (secondsRound == 1) ? "" : ""; min = (minutesRound == 1) ? " : " : " : "; hr = (hoursRound == 1) ? " : " : " : "; //dy = (daysRound == 1) ? " day" : " days, "; document.timeForm.input1.value = "Check again before " + hoursRound + hr + minutesRound + min + secondsRound + sec; newtime = window.setTimeout("getTime();", 1000); } window.onload=getTime; if (days = 0){ days.style.display = "none"; } </script> <form name=timeForm> <input type=text name=input1 size=50 border-style="none" style="display: block; border: none; font-size: 14px; font-family: sans-serif"> </form> </body> </html> 

 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>jQuery Countdown</title> </head> <body> <script language="javascript" type="text/javascript"> function getTime() { now = new Date(); /* Use todays date to calculate tomorrows alarm */ var day = now.getDate() /*console.log('today: ' + day)*/ var monthsAbbrev = [ "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" ]; var index = now.getMonth() var month = monthsAbbrev[ index ] /*console.log('month: ' + month)*/ var year = now.getFullYear() /*console.log('year: ' + year)*/ var monthsWith31days = [ "Jan", "Mar", "May", "July", "Aug", "Oct", "Dec" ]; var monthsWith30days = [ "Apr", "June", "Sept", "Nov" ]; var alarm = "04:30:00 PM" var time = now.toLocaleTimeString() /* "HH:MM:ss AM/PM" */ /*console.log('time: ' + time) console.log('is it true??' + (time >= alarm))*/ if (time >= alarm) { console.log('today is ' + day) var maxIs31 = new RegExp("(" + monthsWith31days.join("|") + ")").test(month) var maxIs30 = new RegExp("(" + monthsWith30days.join("|") + ")").test(month) var monthIsFeb = /(Feb)/.test(month) /*console.log('maxIs31: ' + maxIs31) console.log('maxIs30: ' + maxIs30) console.log('monthIsFeb: ' + monthIsFeb)*/ if (maxIs31) { (day >= 31) ? (day = 1) : ( day +=1 ) } else if (maxIs30) { (day >= 30) ? (day = 1) : ( day +=1 ) } else if (monthIsFeb) { if (parseInt(year, 10) % 4 === 0) { /* its a leap year */ (day >= 29) ? (day = 1) : ( day += 1 ) } else { (day >= 28) ? (day = 1) : ( day += 1 ) } } console.log('tomorrow wil be?? ' + day) } /* Now set tomorrows alarm only if its gone off today */ orderBy = new Date( month +" "+ day +" "+ year +" "+ alarm ); days = (orderBy - now) / 1000 / 60 / 60 / 24; daysRound = Math.floor(days); hours = (orderBy - now) / 1000 / 60 / 60 - (24 * daysRound); hoursRound = Math.floor(hours); minutes = (orderBy - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound); minutesRound = Math.floor(minutes); seconds = (orderBy - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound); secondsRound = Math.round(seconds); sec = (secondsRound == 1) ? "" : ""; min = (minutesRound == 1) ? " : " : " : "; hr = (hoursRound == 1) ? " : " : " : "; //dy = (daysRound == 1) ? " day" : " days, "; document.timeForm.input1.value = "Check again before " + hoursRound + hr + minutesRound + min + secondsRound + sec; newtime = window.setTimeout("getTime();", 1000); } window.onload=getTime; if (days = 0){ days.style.display = "none"; } </script> <form name="timeForm"> <input type="text" name="input1" size="50" border-style="none" style="display: block; border: none; font-size: 14px; font-family: sans-serif"> </form> </body> </html> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM