看下面这段代码
<s:iterator value="pageBean.list">
<li> <span class="afront">&nbsp;&nbsp;&nbsp;
<a href="<%=request.getContextPath()%>/newsContent.action?id=<s:property value="id" />" title="<s:property value="name" />">
<s:property value="name" />
</a>&nbsp;
<img src="<%=request.getContextPath()%>/images/new.gif" />
</span><span class="abehind">[<s:property value="insertDate" />]</span>
</li>
</s:iterator>
我现在要根据<s:property value="insertDate" />的值跟系统的当前日期比较相差的天数来决定<img src="<%=request.getContextPath()%>/images/new.gif" />是否显示,小于七天显示,大于就不显示,怎么做。我的想法是加上
<%
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
Date   current=sdf.parse(sdf.format(new java.util.Date())); 
 %><s:if test='(<s:property value="insertDate" />-<%=current.getTime()%>)/(1000*60*60*24)<=7'> 
<img src="<%=request.getContextPath()%>/images/new.gif" />
</s:if>
现在的问题是<s:property value="insertDate" />怎么转换成和<%=current.getTime()%>相同的格式

解决方案 »

  1.   

    <s:property value="insertData" format="yyyy-MM-dd"/>,这样不知道可以不可以,struts标签是可以的
      

  2.   


    你可以在ACTION中把insertDate属性设置到request中
    request.setAttribute("inserDate",insertDate);然后在JSP中
    <%
       String insertDate = request.getAttribute("insertDate");
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); 
       Date dtinsertDate = sdf.parse(insertDate );
       if((dtinsertDate.getTime()-current.getTime())/(1000*60*60*24) <=7)
    {
    %>
    <img src=" <%=request.getContextPath()%>/images/new.gif" /> 
    <%
    }%>   
      

  3.   

    我知道有个<s:date name="insertData"  format="yyyy-MM-dd"/>但是这个name的值该怎们取?
      

  4.   

    由于在action中pojo对象都是封装在list中的,那我时候要从新定义一个list来封装日期。然后在前台页面顺序输出。
      

  5.   

    你只要在Acition中,把insertDate转换成正确的日期型的字符串,然后SET到REQUEST里就好了
      

  6.   

    <s:if test="(insertDate - currentTime) / (1000*60*60*24) <= 7">貌似s标签可以这么写吧。 currentTime使用前先set一下