How do I calculate the date in jstl?

Asked 1 years ago, Updated 1 years ago, 136 views

Using jstl fmt tag on jsp

Attempt to compute the date.

Date is data is

This will be taken to the string in the format "1986-01-20".

Current Date - Deadline Date = Few days left

I'm trying to use it, but it's really hard

fmt jstl

2022-09-22 21:30

1 Answers

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.


2022-09-22 21:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.