问题
I need to add 30 days to the current system date in timestamp. How can I acheive that? I am having below code:
<%
Date date= new Date();
long time = date.getTime();
Timestamp ts = new Timestamp(time);
%>
<c:set var="currentDate"><%=ts%></c:set>
<c:if test="${startDate lt currentDate}">
<c:if test="${endDate gt currentDate}">
How can I make ts+ 30? Thanks in advance.
回答1:
Use calendar:
Calendar cal=new GregorianCalendar();
cal.add(Calendar.DATE, 30);
Date d=cal.getTime();
回答2:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
Date date= new Date();
Calendar cal = Calendar.getInstance();
cal.setTime (date);
cal.add (Calendar.DATE, 30);
date = cal.getTime ();
%>
<c:set var="currentDate"><%=date%></c:set>
<c:out value="currentDate"/>
来源:https://stackoverflow.com/questions/28374791/how-to-add-30-days-in-a-timestamp-in-jstl