如何检查给定时间是在下午3点之后或不在Rails中?

我想要最简单或最简单的方法,它返回给我布尔值(true / false),具体取决于给定的时间是在下午3点之后,或者与日期无关。

对于前: –

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 

是你所需要的全部。

你只需要使用“时间”function:

  Time.now.hour => 11 

现在你可以根据你想要的时间来评估这个。