String inputDate = "2016-08-20";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate fromDate = LocalDate.parse(inputDate, formatter); // 2016-08-20
LocalDate toDate = LocalDate.now(); // 2016-08-11
long day = ChronoUnit.DAYS.between(fromDate, toDate); // -9
Please refer to ChronoUnit class ~ You can calculate the date easily. LocalDate and ChronoUnit are available from jdk 8~
I calculated on a 'day' basis using ChronoUnit.DAYS.between. You can change the positions of fromDate and toDate depending on whether it is positive or negative.
Instead of DAYS, you can get time, minutes, and elementary school, so use it.
You can use <%%> to implement it directly within jsp, or you can use it by declaring it as a method.
© 2024 OneMinuteCode. All rights reserved.