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?
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"/>.
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.
<c:out> is a JSTL core tag, which is used for displaying server-side variables and hardcoded values on the browser (client).
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:
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}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With