Created
December 20, 2012 10:00
-
-
Save NKjoep/4344305 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