I instantiated a java.util.Date object called myDate in my controller and passed it to my JSP where I have a Joda Time JSP tag configured with this at the top of the page:
<%@taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
and of course the necessary Maven dependencies added to the project via the POM file.
However, when I try to access myDate from the JSP like this:
<joda:format value="${myDate}" style="SM" />
I get this error:
javax.servlet.jsp.JspException:
value attribute of format tag must be a
ReadableInstant or ReadablePartial, was: java.util.Date
Referring to the documentation for the Joda Time JSP tags, I can't tell how I should 'convert' my myDate to a ReadableInstant or ReadablePartial in the context of this JSP?
Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.
You can create a Date object using the Date() constructor of java. util. Date constructor as shown in the following example. The object created using this constructor represents the current time.
Joda-Time provides a comprehensive formatting system. There are two layers: High level - pre-packaged constant formatters. Mid level - pattern-based, like SimpleDateFormat. Low level - builder.
The error message is self-explaining. The JodaTime tags doesn't accept a Java SE standard Date instance, but a JodaTime DateTime instance or whatever implements JodaTime's ReadableInstant or ReadablePartial.
You need to convert it before providing it to the view.
DateTime dateTime = new DateTime(date.getTime());
request.setAttribute("myDate", dateTime);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With