检查当前日期和时间是否在不包括周末的日期范围内

时间:2012-08-13 22:50:55

标签: java datetime jodatime intervals dayofweek

我正在写一个处理读卡门牌的项目。系统必须检查刷卡是否在该特定时间对特定门具有许可。例如,有些卡在周末或工作时间以外是8-20的许可。我如何用Joda-Time编程这样的东西?

现在我有:

//The code below that I have only checks for within a given date and time range.
DateTime start = new DateTime(2012, 1, 1, 0, 0);
DateTime end = new DateTime(2012, 12, 31, 0, 0);
Interval interval = new Interval(start, end);
boolean DateTimeCheck3 = interval.contains(time); // time is predeclared and gets current time from another class

1 个答案:

答案 0 :(得分:1)

使用1 <= time.getDayOfWeek() && time.getDayOfWeek() <= 5您可以确保星期几在1星期一到星期五5之间。