gpt4 book ai didi

ruby-on-rails - 检查当前时间是否在10之前 :27pm

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

找到了很多方法来检查当前小时是否在一个小时范围内。但是,您如何检查当前时间是否在特定分钟时间之前,例如 10:27 pm

当前代码(只比较小时,不比较分钟):

Time.now.getlocal("-05:00").hour.between?(10, 22)

例如,我们的商店营业时间是 上午 9:24 - 晚上 10:27,我们想检查它当前是否营业。

最佳答案

正如 docs 中明确提到的:

You can also do standard functions like compare two times.

我认为你可以这样做:

require 'time'
close_time = Time.parse "10:27 pm"
#=> 2015-11-23 22:27:00 -0800
current_time = Time.now
#=> 2015-11-23 19:38:06 -0800
current_time < close_time
#=> true # means the store is open

late_time = Time.now + 4*60*60
#=> 2015-11-23 23:39:15 -0800
late_time < close_time
#=> false # means the store is close

关于ruby-on-rails - 检查当前时间是否在10之前 :27pm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33884987/

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