Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign fmt:formatDate output to a c:set variable

Tags:

jsp

jstl

I want to do something like this:

<c:set var="strDate" value="<fmt:formatDate value='${obj.dateIn}' pattern='ddMMyyyy'/>"/>

to obtain the date as (formatted) string and assign it to a variable for later use but it isn't working, any ideas on how to do it in jsp-jstl?

The only way I find around it is to create a "fake" getter for the object java class that outputs the desired date as a String usign SimpleDateFormat.format(..) but me thinks it's not very orthodox and want to leave the underlying classes alone.

like image 444
danirod Avatar asked Feb 03 '11 12:02

danirod


2 Answers

<fmt:formatDate value=".." pattern=".." var="strDate" />

the var attribute is:

Name of the exported scoped variable which stores the formatted result as a String.

like image 53
Bozho Avatar answered Oct 07 '22 01:10

Bozho


First format the date after assign dateFormated to variable

Put it this way:

<fmt:formatDate value='${obj.dateIn}' pattern='ddMMyyyy' var="searchFormated" />
<c:set var="strDate" value="${searchFormated}"/>
like image 35
borchvm Avatar answered Oct 07 '22 03:10

borchvm