Currently working on a site where I use moment.js. I want to use jquery only.
I get the current minute using:
var minute = moment().minute();
but I want to set an alarm starting at the nearest next 5 minute mark.
So say it's 8:38pm now, var minute would be 38. I'd want to set the input to a value of 40 (that is, 40 minutes)
So where my options are:
<select id="minuteID">
<option value="0">00</option>
<option value="5">05</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="35">35</option>
<option value="40">40</option>
<option value="45">45</option>
<option value="50">50</option>
<option value=55>55</option>
</select>
And I can input the item like so:
var minute = moment().minute();
$("#minuteID option[value=" + minute + "]").prop("selected", "selected");
How do I make it so that instead of finding the exact option minute, it finds it at intervals of 5 (to the nearest 5 marker).
You can directly call function momentInstance. valueOf(), it will return numeric value of time similar to date. getTime() in native java script.
The moment(). minute() Method is used to get the minutes from the current time or to set the minutes. moment(). minutes();
add(minutes, 'minutes') . format('LTS');
minute = 5 * Math.round( minute / 5 );
will do as you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With