开发者

How to check given time is after 3pm or not in Rails?

开发者 https://www.devze.com 2023-03-23 02:53 出处:网络
I want easiest o开发者_StackOverflow中文版r simplest method which returns me boolean value (true/false) depending on the given time is after 3 pm or not irrespective of date.

I want easiest o开发者_StackOverflow中文版r simplest method which returns me boolean value (true/false) depending on the given time is after 3 pm or not irrespective of date.

for ex:-

   def after_three_pm(time)
     //some code here 
   end

   time= Time.now # Tue Jul 26 11:17:27 +0530 2011  THEN
   after_three_pm(time)  # should return false

   time= Time.now # Tue Jul 26 15:17:27 +0530 2011  THEN
   after_three_pm(time)  #  should return true


def after_three_pm(time)
  time.hour >= 15
end

is all you need.


you simply need to use the "time" function:

    Time.now.hour
=> 11

Now you can just evaluate this against the hour you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号