gpt4 book ai didi

ruby-on-rails - 如何在 Rails 中检查给定时间是否在下午 3 点之后?

转载 作者:数据小太阳 更新时间:2023-10-29 07:44:28 25 4
gpt4 key购买 nike

我想要最简单或最简单的方法,该方法根据给定时间是否在下午 3 点之后返回 bool 值(真/假),而不管日期如何。

例如:-

   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

就是你所需要的。

关于ruby-on-rails - 如何在 Rails 中检查给定时间是否在下午 3 点之后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6828294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com