danirod
danirod

Reputation: 1021

Assign fmt:formatDate output to a c:set variable

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.

Upvotes: 15

Views: 23680

Answers (2)

Borja
Borja

Reputation: 3610

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}"/>

Upvotes: 1

Bozho
Bozho

Reputation: 597106

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

the var attribute is:

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

Upvotes: 37

Related Questions