• <i id='lJrJy'><tr id='lJrJy'><dt id='lJrJy'><q id='lJrJy'><span id='lJrJy'><b id='lJrJy'><form id='lJrJy'><ins id='lJrJy'></ins><ul id='lJrJy'></ul><sub id='lJrJy'></sub></form><legend id='lJrJy'></legend><bdo id='lJrJy'><pre id='lJrJy'><center id='lJrJy'></center></pre></bdo></b><th id='lJrJy'></th></span></q></dt></tr></i><div id='lJrJy'><tfoot id='lJrJy'></tfoot><dl id='lJrJy'><fieldset id='lJrJy'></fieldset></dl></div>

    1. <small id='lJrJy'></small><noframes id='lJrJy'>

      • <bdo id='lJrJy'></bdo><ul id='lJrJy'></ul>
      <legend id='lJrJy'><style id='lJrJy'><dir id='lJrJy'><q id='lJrJy'></q></dir></style></legend>

    2. <tfoot id='lJrJy'></tfoot>

        在 JSP 中使用 struts 2 比较日期

        Comparing dates using struts 2 in JSP(在 JSP 中使用 struts 2 比较日期)
          • <i id='XBto3'><tr id='XBto3'><dt id='XBto3'><q id='XBto3'><span id='XBto3'><b id='XBto3'><form id='XBto3'><ins id='XBto3'></ins><ul id='XBto3'></ul><sub id='XBto3'></sub></form><legend id='XBto3'></legend><bdo id='XBto3'><pre id='XBto3'><center id='XBto3'></center></pre></bdo></b><th id='XBto3'></th></span></q></dt></tr></i><div id='XBto3'><tfoot id='XBto3'></tfoot><dl id='XBto3'><fieldset id='XBto3'></fieldset></dl></div>

            <tfoot id='XBto3'></tfoot>
            <legend id='XBto3'><style id='XBto3'><dir id='XBto3'><q id='XBto3'></q></dir></style></legend>

            <small id='XBto3'></small><noframes id='XBto3'>

              <bdo id='XBto3'></bdo><ul id='XBto3'></ul>

                  <tbody id='XBto3'></tbody>

                1. 本文介绍了在 JSP 中使用 struts 2 比较日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 Struts2

                  One is returned from the backend  (test.currentDate) == "2012-11-15)"
                  The other one I just set "2014-10-19"
                  

                  如何比较这两个日期?

                  我的代码如下:

                  <s:set name="currentDate"  value="%{test.currentDate}"/>
                  <s:set name="futureDate" value="2014-10-19"/>
                  <s:if test="%{#currentDate.before(#futureDate)}">
                      <s:text name="test"/> <s:date name="test.currentDate" format="MM/yy"/> 
                  </s:if>
                  <s:else>
                      <s:text name="test2"/>
                  </s:else>
                  

                  推荐答案

                  在上面您尝试将字符串与导致问题的日期对象进行比较.我建议您编写一个帮助类来比较日期并利用 OGNL 静态方法访问.OGNLBasics-Accessingstaticproperties

                  In the above you were trying compare string with date object that's causing the problem. I suggest you to write a helper class to compare date and take the advantage of OGNL static method access. OGNLBasics-Accessingstaticproperties

                      <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();
                  }
                  

                  这篇关于在 JSP 中使用 struts 2 比较日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  • <bdo id='N6MMR'></bdo><ul id='N6MMR'></ul>

                  • <legend id='N6MMR'><style id='N6MMR'><dir id='N6MMR'><q id='N6MMR'></q></dir></style></legend>

                        <tbody id='N6MMR'></tbody>

                      • <tfoot id='N6MMR'></tfoot>
                        1. <small id='N6MMR'></small><noframes id='N6MMR'>

                            <i id='N6MMR'><tr id='N6MMR'><dt id='N6MMR'><q id='N6MMR'><span id='N6MMR'><b id='N6MMR'><form id='N6MMR'><ins id='N6MMR'></ins><ul id='N6MMR'></ul><sub id='N6MMR'></sub></form><legend id='N6MMR'></legend><bdo id='N6MMR'><pre id='N6MMR'><center id='N6MMR'></center></pre></bdo></b><th id='N6MMR'></th></span></q></dt></tr></i><div id='N6MMR'><tfoot id='N6MMR'></tfoot><dl id='N6MMR'><fieldset id='N6MMR'></fieldset></dl></div>