2017-10-18 87 views
0

我试图确定日期是否在60天内(与今天的日期相比)。尝试在jsp中执行类似于@Adjust的操作

如果服务日期在60天内,则列将显示“是”,另一方面,如果日期超过60天,则列将显示“否”。

我知道,如果在Lotus Notes应用程序,我可以用这个公式来实现它

@If(@Adjust(ServiceDate; 0; ; 60; 0; 0; 0) >= @Today; "Yes"; "No") 

现在,我尝试做在jsp文件类似的东西(没有Lotus Notes应用程序)

<display:table name="${serviceList}" class="its" uid="row" 
     sort="list" pagesize="10" requestURI="service_view" export="false" defaultsort="2" defaultorder="descending" id="serviceTable"> 

    <display:column style="width: 30%" title="Service Name" property="serviceName" /> 

    <!-- this column is for display --> 
    <display:column style="width: 10%" title="Service Date" property="serviceDate" format="{0,date,dd-MM-yyyy}" /> 

    <!-- this service date is for calculation --> 
    <display:column title="Service date"> 

    <fmt:formatDate value="${attr.row.serviceDate}" var="formatservicedate" 
      type="date" pattern="dd-MM-yyyy" /> 
    <c:set var= "servicedate" value = "${formatservicedate}" /> 
    <c:out value = "${servicedate}" /> 
    </display:column> 

    <!-- this today's date is for calculation --> 
    <display:column title='today date'> 

    <%@page import="java.text.SimpleDateFormat, java.util.Calendar, java.text.DateFormat"%> 
    <% 
     DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); 
     Calendar cal = Calendar.getInstance();   
    %> 

    <%-- try to use variable to show --%> 
    <!-- get today's date in dd/mm/yyyy by variable --> 

    <c:set var= "todaydate" value = "<%= dateFormat.format(cal.getTime()) %>" /> 
    <c:out value = "${todaydate}" /> 
    </display:column> 

    <display:column title='Is within 60 days'> 
     <%@page import="java.text.SimpleDateFormat, java.util.Calendar, java.text.DateFormat"%> 
    <% 
     DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); 
     Calendar cal = Calendar.getInstance();   
    %> 

     <!-- get today's date in dd/mm/yyyy by variable --> 
    <c:set var= "todaydate" value = "<%= dateFormat.format(cal.getTime()) %>" /> 

    <!-- get service date by variable--> 
    <fmt:formatDate value="${attr.row.serviceDate}" var="formatservicedate" 
      type="date" pattern="dd/MM/yyyy" /> 
    <c:set var= "servicedate" value = "${formatservicedate}" /> 

    <!-- I tried <c:if test="${servicedate + 60 ge todaydate}"> but not work --> 
    <!-- I am not sure how to plus 60 days for service date in the logic --> 
    <c:if test="${servicedate ge todaydate}"> 
    <p><b>Yes</b></p> 
    </c:if> 
    <c:if test="${!servicedate ge todaydate}"> 
    <p><b>No</b></p> 
    </c:if> 

    </display:column> 
</display:table> 

所以我想知道是否有可能在jsp中执行类似@Adjust()的操作来确定日期是在60天内?非常感谢。

+0

我在考虑先给服务日期添加60天,然后用它来com今天的日期。如果日期> =今天的日期,该列将显示“是”,否则该列将显示“否”。我在这个逻辑中错过了什么吗? – Learner

回答

0

最后我弄明白了。

先通过变量获取今天的日期和服务日期。

然后准备逻辑

找出方程每天天

Math.abs(variable1.getTime() - variable2.getTime()); 

60 seconds * 60 minutes * 24 hours 

查找公式如果天除以一天< = 60,表明是的,否则节目没有

相关问题