How do you get the date/time range for “today” using the Joda date/time library in Java?

后端 未结 6 1708
故里飘歌
故里飘歌 2021-01-17 07:59

Assuming this is how you get the current time in Joda time:

DateTime now = new DateTime();

How do you calculate values for the variables

6条回答
  •  一向
    一向 (楼主)
    2021-01-17 08:33

    As a Kotlin extension function it looks like this:

    fun DateTime.isOnSameDay(timeOnDayToCheck: DateTime) =
      timeOnDayToCheck.toLocalDate().toInterval(this.zone).contains(this)
    

    This does not contain times equaling the end of the day (start is included) so maybe add an "or"-case with interval.getEnd().isEqual(this)).

提交回复
热议问题