Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note: This answer is intended to guide the poster to the solution and a better understanding of JS, not to give the solution.</p> <p>The way the current code works is by first getting a date object and then setting the time on that object to either 24:00 (next midnight) or 12:00 (next noon). It works this out by checking what the current hours value is for the time (&lt;12 means noon is next, otehrwise midnight is next). It then returns that newly modified date object showing the date that I presume the countdown is designed to run until.</p> <p>So the core of the problem is you need to return a different date object which means you want to set the minutes to something of your choosing (and the seconds and milliseconds to 0).</p> <p>For what you want to do you would be wanting to use the getMinutes and setMinutes functions on the Date Object to check the current date and then set the appropriate minute (and seconds and milliseconds values). Of course if your current time is 01:59 then you may need to change the hours to give 02:00 so you may in fact still want to use setHours (since this does allow you to set hours and minutes).</p> <p>To work out what your new minutes value is will hopefully be something you can do. You jsut need to round up to the nearest 5 and deal appropriately with the above mentioned situation where you are rounding up to an hour.</p> <p>Documentation on these above methods can be found on the msdn site:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/f4a5xhxy%28v=vs.94%29" rel="nofollow">setHours</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/815z9tc9%28v=vs.94%29" rel="nofollow">getHours</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/t919zcb7%28v=vs.94%29" rel="nofollow">getMinutes</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/3sbd2ey3%28v=vs.94%29" rel="nofollow">setMinutes</a></li> </ul> <p><strong>Edit to add some code</strong></p> <pre><code>var hours = until.getHours(); var minutes = until.getMinutes(); var targetMinutes = Math.ceil((minutes+1)/5)*5; if (targetMinutes==60) { targetMinutes = 0; hours = hours+1; } until.setHours(hours, targetMinutes, 0, 0); </code></pre> <p>You might be able to write the above a little more efficiently and you might need to check what it does around boundaries like midnight properly too (it seems to work but you should always test code thoroughly). Hopefully you can understand what its up to. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload