【发布时间】:2020-11-18 16:22:17
【问题描述】:
我想创建一个方法来告诉我我是否在两个小时之间(即使我选择不同日期的小时数) 例如:
Current time: 20:00, start: 21:00, end: 23:00 -> returns false
Current time: 22:00, start: 21:00, end: 23:00 -> returns true
Current time: 01:00, start: 21:00, end: 8:00 -> returns true
Current time: 22:00, start: 21:00, end: 20:00 -> returns true
Current time: 05:00, start: 21:00, end: 4:00 -> returns false
有没有简单干净的方法来做到这一点?
【问题讨论】:
-
I want to create a method that tells me if i'm between two hours (even if I choose hours from different days)...Is there any simple and clean way to do this?- 如果没有日期,最简洁的方法是在所有情况下都返回true。 ?????? -
即使此处给出的答案比其他问题下接受的答案更好,我也选择关闭为副本。那边有一个更彻底的answer by Basil Bourque,我相信值得你关注。