I'm using JavaScript to get the current time, and I do it every two hours starting at 12 pm I want to count / P>
I currently have a code that reset for up to 2 hours, but I want to do it from time to time 12:00.
I have my current code seeks to 12:00 start to say, when access to certain pages or I do it any other way (open to suggestions).
Thanks a lot!
var startTime = new Date (), end time = new Date (); h = document KgetElementById ( "JS-hour"), minutes Ilem = document.getElementById ( 'js-minute '), Second eel = document. GetElementById (' js-sec '); // Expiry time expiration.SetShare (End time. Guesthors () + 2); ExpiryTime.setMinutes (expiryTime.getMinutes (++)); ExpiryTime.setSeconds (expiryTime.getSeconds () + 0); Var diffInMs = expiryTime - STARTTIME, diffInSecs = Math.round (diffInMs / 1000), amountOfHours = Math.floor (diffInSecs / 3600), amountOfSeconds = diffInSecs - (amountOfHours * 3600), amountOfMinutes = Math.floor (amountOfSeconds / 60), Zodiac-second-half-hour = zodiac-half-seconds-(volumeoffimine * 60); // set up the countdown timer set up // hour display (the amount of the withdrawal & gt; 0) {hourElem.innerHTML = (Matraofr & lt; 10)? '0' + zodiacal + ':': sum: half-hours + ':'; } And (hour) altimeter HTML = '00: '; } // set up the minute, then (amountOfMinutes & gt; 0) {minuteElem.innerHTML = (amountOfMinutes & lt; 10)? '0' + zodiac amounts + ':': volumeoffimes + ':'; } Else {minuteElem.innerHTML = '00: '; } // // set up, then (amountOfSeconds & gt; 0) {secondElem.innerHTML = (amountOfSeconds & lt; 10)? '0' + Zodiac Offset: Zodiac Offsand; } Else {secondElem.innerHTML = '00'; } Function countdown () {var dateNow = new date (); // we have values that are not at the end of the timer, then continues the countdown (expiryTime & gt; dateNow) {// reference var-hour current countdown = parseInt (hourElem.innerHTML); Min = persian (min.la.perfect), second = purse (secondhelm builder html); // hour update if needed (minutes == 0 & amp; seconds == 0) {if (hours = 0!) {--hours; HourElem.innerHTML = (hours & lt; 10)? '0' + (hours) + ':': (hours) + ':'; MinuteElem.innerHTML = '59: '; Second Elm Wiener HTML = '59'; Return; } And (hour) Aleemian HTML = '02: '; MinuteElem.innerHTML = '00: '; SecondElem.innerHTML = '00'; Return; }} // Update the minute if necessary (seconds == 0) {if (min> gt; 0) {--minutes; MinuteElem.innerHTML = (minutes> 10)? Min + ':': '0' + min + ':'; } Else {minuteElem.innerHTML = '59' + ':'; } Second return Elem.innerHTML = '59'; } And {--seconds; SecondElem.innerHTML = (seconds and lieutenant; 10)? '0' + seconds: seconds; }} And {expiryTime.setHours (expiryTime.getHours () + 2); ExpiryTime.setMinutes (expiryTime.getMinutes (++)); ExpiryTime.setSeconds (expiryTime.getSeconds () + 0); }} Window.onload = function () {// Start Countdown! CountDownInterval = setInterval (countdown, 1000); }
After my comment you need to change how you change timer seeds.
If you calculate the number of seconds from the midnight to the current date, then you are scheduling time to end the 2 hour period from the current system time.
So you will know how to start seeds.
There are 7200 seconds in 2 hours if you take the number of seconds from midnight and you use MOD to set the balance, then you will decide how far you are in a 2 hour block. Then use the remaining 7200.
From there you can calculate the number of hours, minutes and seconds, until the countdown ends.
(* Starting a sound like homework I will not post any code)
Comments
Post a Comment