Find the Median Date between two dates using Java 8

Sriram Ilango :

I'm finding it difficult that what it sounds.

So, I have a max date and a min date and I need to find the median date between these two dates. I use Java 8 to find my max and min dates,

LocalDate gerbutsmin = YearMonth.now().plusMonths(2).atDay(1);
LocalDate gerbutsmax = YearMonth.now().plusMonths(15).atDay(1);

How would I go ahead after this? Maybe I need to switch back to Calander?

nytez :
LocalDate gerbutsmin = YearMonth.now().plusMonths(2).atDay(1);
LocalDate gerbutsmax = YearMonth.now().plusMonths(15).atDay(1);

LocalDate median = gerbutsmin.plusDays(ChronoUnit.DAYS.between(gerbutsmin, gerbutsmax) / 2);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=111754&siteId=1