How to add 30 days in a timestamp in jstl

时间秒杀一切 提交于 2019-12-24 08:58:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!