Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsp

jstl

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?

like image 480
Srinivasan Avatar asked Jan 03 '11 18:01

Srinivasan


People also ask

What is the use of <C out> tag?

The <c:out> tag displays the result of an expression. This is almost similar to the way <%= %> works. The difference here is that <c:out> tag lets you use the simpler "." notation to access properties. For example, to access customer.address.street, use the tag <c:out value = "customer.address.street"/>.

How to display date in string format in C#?

This article only focuses upon how we can display Date in string format in C# so we would not discuss all the remaining constructors. 2. DateTime.now () method: To get the current date and time DateTime.now () method of the DateTime struct is used.

What is <C out> tag in JSTL?

<c:out> is a JSTL core tag, which is used for displaying server-side variables and hardcoded values on the browser (client).

How to escape the XML tags in C out tag?

The < c:out > tag automatically escape the XML tags. Hence they aren't evaluated as actual tags. Let's see the simple example of c:out tag:


1 Answers

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}" />
like image 62
BalusC Avatar answered Oct 21 '22 05:10

BalusC