For example i have two dates:
2018-11-30 18:00:00
2018-12-01 00:00:00
How you can see, that less then 24 hours difference, but I need to recognize that a one day of differnce, and i can't just subtract, cause of month change. In output i need to return int count of days.
In c# it will be just:
(EndDate - StartDate).TotalDays
What Java code will be similar?
I searched somewhere before I asked, but that didn’t solve the problem. Here’s my attempt after searching:
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime d1 = LocalDateTime.parse("2018-11-30 18:00:00", dtf);
LocalDateTime d2 = LocalDateTime.parse("2018-12-01 00:00:00", dtf);
long days = ChronoUnit.DAYS.between(d1, d2);
System.out.println("Days: " + days); // Days: 0
I wish to get 1 day of difference.