判断当前是否在某个范围内
How to find if a date-time is in given time slot in Groovy? | < One Byte at a Time />
public Boolean NowBetween(String beg, String end, String format = "HH:mm") { def timeBeg = new SimpleDateFormat(format).parse(beg); def timeEnd = new SimpleDateFormat(format).parse(end); def timeRange = timeBeg..timeEnd; def timeNow = new SimpleDateFormat(format).format(new Date()); def time = new SimpleDateFormat(format).parse(timeNow); return timeRange.containsWithinBounds(time); }
参考文献
K4NZ / 处理日期时间
Groovy - Dates & Times - Tutorialspoint
DateTimeExtensions (Groovy 3.0.6)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。