jsp - Getting current date in JSTL EL and doing arithmetic on it -


without using scriptlets, what's correct way doing date arithmetic in jsp?

here examples i'm trying do:

  1. get current year (yyyy)
  2. subtract current year 1 previous year (yyyy)

thanks!

use <jsp:usebean> construct new date. use jstl <fmt:formatdate> year out of it. use el substract it.

<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <jsp:usebean id="now" class="java.util.date" /> <fmt:formatdate var="year" value="${now}" pattern="yyyy" /> <p>current year: ${year}</p> <p>previous year: ${year - 1}</p> 

result:

current year: 2011

previous year: 2010

note pattern full year yyyy, not yyyy.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -