-
-
Save coverboy/7bb08a5e4f6ee3f39b0e3ce255fa17d0 to your computer and use it in GitHub Desktop.
print out the current year within a jsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%-- version1: java style --%> | |
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | |
<%@page import="java.util.Date"%> | |
<%@page import="java.util.Calendar"%> | |
<% pageContext.setAttribute("currentYear", java.util.Calendar.getInstance().get(java.util.Calendar.YEAR)); %> | |
Current year is: <c:out value="${currentYear}" /> | |
<%-- version2: JSTL style --%> | |
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | |
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> | |
<jsp:useBean id="date" class="java.util.Date" /> | |
<fmt:formatDate value="${date}" pattern="yyyy" var="currentYear" /> | |
Current year is: <c:out value="${currentYear}" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment