判断当前是否在某个范围内

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)


相关文章:

  • 2021-07-09
  • 2022-01-07
  • 2021-09-30
  • 2021-06-05
  • 2021-09-27
猜你喜欢
  • 2022-02-21
  • 2022-12-23
  • 2021-11-28
  • 2021-04-29
  • 2021-05-14
  • 2021-08-04
  • 2021-09-29
相关资源
相似解决方案