Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to find days difference between two org.threeten.bp.LocalDateTime dates in java

I have two dates in an org.threeten.bp.LocalDateTime object. I need to find the difference between these two dates in terms of days.

like image 795
gaurav Avatar asked Oct 05 '15 18:10

gaurav


People also ask

What is the difference between date and LocalDateTime in Java?

A date-time without a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30 . LocalDateTime is an immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second.

What is the difference between two LocalDateTime in Java 8?

In Java 8, we can use Period , Duration or ChronoUnit to calculate the difference between two LocalDate or LocaldateTime . Period to calculate the difference between two LocalDate . Duration to calculate the difference between two LocalDateTime . ChronoUnit for everything.


1 Answers

Use org.threeten.bp.temporal.ChronoUnit.between:

long days = ChronoUnit.DAYS.between(fromDate, toDate);  
like image 117
wero Avatar answered Sep 19 '22 14:09

wero