Probably asked before but can't find answer for this. How do I check if time is greater than 17:30 every day?
My case is that I would need to check if current time is greater than 17:30 on Monday to Friday and if today is Saturday I have to check if time is greater than 15:30.
I do prefer use of Moment.js.
Here an example with moment.js
function check() {
var now = moment();
var hourToCheck = (now.day() !== 0)?17:15;
var dateToCheck = now.hour(hourToCheck).minute(30);
return moment().isAfter(dateToCheck);
}
console.log(check())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
You can just check for the time using Date()
. Seriously, you don't need a big plugin for this:
var curTime = new Date();
var day = curTime.getDay();
curTime = parseInt(curTime.getHours() + "" + ("0" + curTime.getMinutes()).substr(-2) + "" + ("0" + curTime.getSeconds()).substr(-2));
if ((curTime > 173000 && day > 0 && day < 6) || (curTime > 153000 && day <= 0 && day >= 6))
console.log("It's a good time!");
else
console.log("It's not a good time!");
Let me know if there's a case, this fails!
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