How to calculate the number of days in a period?

后端 未结 3 1468
独厮守ぢ
独厮守ぢ 2020-11-27 19:10

For the following Period calculation:

Period.between(LocalDate.of(2015, 8, 1), LocalDate.of(2015, 9, 2))

the result is:

<
3条回答
  •  广开言路
    2020-11-27 19:47

    There's a specific object depending at the amount of time you'd like to deal with. This page here is very useful explaining which is best for your scenario.

    The ChronoUnit.between method is useful when you want to measure an amount of time in a single unit of time only, such as days or seconds

    LocalDate localDateStartDate = LocalDate.of(2016, 06, 10);
    LocalDate localDateEndDate = LocalDate.of(2016,06,23);
    long days = ChronoUnit.DAYS.between(localDateStartDate, localDateEndDate);
    

提交回复
热议问题