Skip to content

Instantly share code, notes, and snippets.

@NKjoep
Created December 20, 2012 10:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NKjoep/4344305 to your computer and use it in GitHub Desktop.
Save NKjoep/4344305 to your computer and use it in GitHub Desktop.
print out the current year within a jsp
<%-- 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