How to convert a java Date to a ReadableInstant for Joda Time inside a JSP?
العربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
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?
Answer |
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);