Is it possible to create a date value in Expressio

2020-02-28 03:10发布

问题:

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?

回答1:

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


回答2:

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