Skip to content
𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

Display current year in JSP using JSTL

Posted on January 1, 2012September 25, 2021 By sastrija

As a programming standard, we don’t use java scriptlets in our JSP files. The best practice is to use JSTLs in JSP files to load the dynamic contents.

Displaying current year in JSP is one of the common requirement, at least for copyright messages.

Displaying current year in JSP can be achieved by using the following JSTL code.

<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:useBeanid="currentDate"class="java.util.Date"/>
<fmt:formatDatevar="year"value="${currentDate}"pattern="yyyy"/>
<p>Β© 2010-${year} ABCD Inc. All rights reserved</p>

For Java 8 or above we can print current year with single line of code

<%= LocalDate.now().getYear() %>

Related

Uncategorized

Post navigation

Previous post
Next post
©2025 𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ | WordPress Theme by SuperbThemes