在上面,您尝试将字符串与导致问题的日期对象进行比较。我建议您编写一个帮助类来比较日期并利用 OGNL 静态方法访问。OGNLBasics-访问静态属性
<s:set var="currentDate" value="%{new java.util.Date()}"/>
<s:set var="futureDate" value="%{new java.util.Date()}"/>
<s:property value="{#currentDate}"/>
<s:property value="{#futureDate}"/>
<s:if test="%{@com.mycompany.temp.strtus2.example.HelloWorld@compareDate(#currentDate, #futureDate)}">
<div>Do your stuff</div>
</s:if>
<s:else>
<div>else condition</div>
</s:else>
实用类
public static boolean compareDate(Date currentDate, Date futureDate) {
boolean flag = false;
if (removeTime(currentDate).equals(removeTime(futureDate))) {
flag = true;
}
return flag;
}
public static Date removeTime(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}