14

Is it possible to create a date value in JSTL Expression Language (EL) without using scriptlets? Here is a snippet of some of the legacy code I'm trying to refactor to only use EL.

<td><%=new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm z").format(new java.util.Date())%></td>

Apparently it prints out the current date and time. I know I can format a date using EL, but can I get a date using EL?

bakoyaro
  • 2,550
  • 3
  • 36
  • 63

2 Answers2

23

I don't think you can do this in EL. But how about this, no scriptlets here

<jsp:useBean id="today" class="java.util.Date" scope="page" />
<fmt:formatDate value="${today}" pattern="MM.dd.yyyy" />
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
1

Thid would be helpfull if you use spring webflow framework

if you define this on the flow.xml

<on-start>
    <set name="flowScope.now" value="new java.util.Date()" />
</on-start>

You can get the value like this

<fmt:formatDate value="#{now}" pattern="MM.dd.yyyy" />
Federico Traiman
  • 1,191
  • 1
  • 13
  • 18