How to display a date by using c:out tag in some format
Asked Answered
V

2

11

I am using JSTL. I want to display a date in JSP using <c:out ..> tag.

I tried <c:out value = "<fmt:formatdate value = '${datevar}'"/>.

But it displays as <fmt:formatdate value = '${datevar}' in the HTML.

What needs to be changed to display date with expected format?

Vitta answered 3/1, 2011 at 18:37 Comment(0)
D
24

You don't need <c:out> and the tag is actually called <fmt:formatDate> (note the uppercase D).

<fmt:formatDate value="${datevar}" pattern="MM/yyyy" />

If you actually want to store it in some variable to redisplay later in <c:out>, then use var attribute.

<fmt:formatDate value="${datevar}" pattern="MM/yyyy" var="newdatevar" />
...
<c:out value="${newdatevar}" />
Duffey answered 3/1, 2011 at 18:39 Comment(1)
Then specify that in the pattern attribute. I updated the answer. See also documentation: download.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fmt/… Note that YYYY is an invalid pattern for years, it should be yyyy. See also download.oracle.com/javase/6/docs/api/java/text/…Duffey
F
-2

You can try this

<C: out value="java.util.Date()"/>

Let me know if it worked for you. Bye.

Filippa answered 17/8 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.