Getting current date in JSTL EL and doing arithmetic on it
问题 Without using scriptlets, what's the correct way for doing date arithmetic in JSP? Here are examples what I'm trying to do: Get current year (YYYY) Subtract current year by one to get previous year (YYYY) Thanks! 回答1: Use <jsp:useBean> to construct new Date. Use JSTL <fmt:formatDate> to get the year out of it. Use EL to 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}"