2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Formatting a long timestamp into a Date with JSTL

I have a requirement where I am getting the date as long timestamp but need to display this in a date format.

I tried to achieve this by using JSTL,Since I am new in this failed.  


The parseDate and formatDate tags work, but they work with Date objects. You can call new java.util.Date(longvalue) to get a date object, then pass that to the standard tag.

So first of all you can convert your timestamp into Date and continue.

long longvalue = ...;//from database.
java.util.Date dateValue = new java.util.Date(longvalue);
request.setAttribute("dateValue", dateValue);

put it on the request and then you can access it in your tag like this.

<fmt:formatDate value="${dateValue}" pattern="MM/dd/yyyy HH:mm"/>

Answer is