我正在尝试确定日期是否在60天内(与今天的日期相比)。
如果服务日期在60天内,该列将显示“是”,另一方面,如果日期超过60天,该列将显示“否”。
我知道如果在莲花笔记中应用,我可以用这个公式来实现它
@If(@Adjust(ServiceDate; 0; ; 60; 0; 0; 0) >= @Today; "Yes"; "No")
现在,我尝试在jsp文件中做类似的事情(没有莲花笔记应用程序)
<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 :(得分:0)
最后我弄清楚了。
首先按变量获取今天的日期和服务日期。
然后准备逻辑
找出一天的等式
60 seconds * 60 minutes * 24 hours
查找方程式
Math.abs(variable1.getTime() - variable2.getTime());
如果天数除以<= 60,则显示是,否则显示否