只比较时间,没有日期? [英] Comparing times only, without dates?
本文介绍了只比较时间,没有日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个方法来检查 Time.now
是否在商店的营业时间和关闭时间之间.
I need to write a method that will check if Time.now
is in between the open hours and the close hours of a shop.
营业时间和营业时间都保存为 Time 对象,但我无法正确比较它,因为商店将营业时间保存在 2012/2/2
,因此营业时间将类似于:
The open and close hours are saved as a Time object but I can't compare it corectly because the shop saved its hours at 2012/2/2
so the open hours will be something like:
2012-02-02 02:30:00 UTC
和 Time.now
将是:
07:23 +0200
如何只比较时间部分而不比较日期部分?
How can I compare just the time part without the date part?
推荐答案
可以比较Time
不带日期部分,例如如下:
You can compare the Time
without a date part, for example, as follows:
time1.utc.strftime( "%H%M%S%N" ) <= time2.utc.strftime( "%H%M%S%N" )
这篇关于只比较时间,没有日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文