views:

298

answers:

2

I get following varaiable, but I cannot format Integer, so is there any way to convert Integer to Date in JSP page?

<fmt:formatDate value="${c.dateInIntegerValue}" pattern="dd.MM.yyyy hh:mm"/>
+2  A: 

How about

<fmt:formatDate value="${new Date(c.dateInIntegerValue)}" pattern="dd.MM.yyyy hh:mm"/>
ammoQ
He has an int not a long, so I wonder if any "rebasing" might be needed in doing the conversion, hence my suggestion to make the class responsible for the conversion.
djna
I am still confused how you can put a date into `int`, even if you can its a bad idea.
Adeel Ansari
djna: sure, the int likely needs to be multiplied with 1000 (e.g. unix date) or even 86400000 (e.g. Excel date). Adapting the class is definitely better, if the project allows it.
ammoQ
-1: you cannot construct objects in EL.
BalusC
+2  A: 

You don't say what class "c" is, but if you have control of it I would add an accessor

c.dateAsDate()

and put the logic for the conversion into the java class. You can put bits of Java for the conversion into your JSP but the danger of doing that is that you end up with lots of little bits of non-reusable Java scattered across your JSPs

djna
public Date getCreatedAsDate() { return new Date(Long.valueOf(created)); }I tried this, but it throws "javax.servlet.ServletException: Attempt to coerce a value of type "java.lang.Integer" to type "java.util.Date" error
newbie
Oh I had older version commented as <!-- --> but it still was run as code, i sohuld have used <%-- --%> tags to comment old code in jsp. So now it is working thnx.
newbie