I have a date field in database which store just date without time. Now I want to know the number of days difference in current date and my date field while displaying that in jsp page.
so I should have like
databaseDate(2012-11-30) - currentDate(2012-11-27) = 3 days
There’s nothing like that in standard JSTL. A custom EL function would be your best bet.
First implement some static methods which performs the job:
If you register it as follows in
/WEB-INF/functions.tld:then you’ll be able to use it as follows, provided that
#{bean.date}returns a fullworthyjava.util.Date:The implementation is free to your choice. I’d personally prefer Joda Time:
Or if you’re restricted to standard Java API, fall back to the well known
Calendarboilerplate (unfortunately, JSR-310 didn’t made it into Java 7, we’ve to wait for Java 8):