Weekend filter for Java 8 LocalDateTime

前端 未结 6 1106
春和景丽
春和景丽 2021-02-20 03:47

I want to write a boolean valued function which returns true if the given LocalDateTime falls between two specific points in time, false otherwise.

Specific

6条回答
  •  花落未央
    2021-02-20 04:33

    Hope this helps:

    LocalDateTime localDateTime = LocalDateTime.now(DateTimeZone.UTC);
    int dayNum = localDateTime.get(DateTimeFieldType.dayOfWeek());
    boolean isWeekend = (dayNum == DateTimeConstants.SATURDAY || dayNum == DateTimeConstants.SUNDAY);
    

    This is the simplest way for doing it without using many private constants.

提交回复
热议问题