I want to check whether the current time is in between 10AM and 10PM. How can I do the check?
You can define a Range and check for the inclusion.
(10..22).include?(Time.new.hour)
# => true
Your code will be
if (10..22).include?(Time.new.hour)
# do whatever you want
end
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