JSTL时间格式化项目小试

  我在之前的博客中虽然详尽的介绍了JSTL在各个载体中的用法,也介绍了它和EL的共同使用的好处,但是只是顺便提了一下JSTL的格式化。

  今天在项目中遇到了一个小问题,也就想到这,马上就开始实践了一下,效果还是不错的。

  问题:

  

我有两个变量beginTime和finishTime,他们都是Date类型的,在界面的日历控件中获取到的时间都是yyyy-MM-dd类型的,但是存到数据库就会变成yyyy-MM-dd 0000:00的类型,也就是自动补全了时分秒。因此,从界面显示的时候,也就是成了yyyy-MM-dd 0000:00这种类型,后面的000是无意义的,所以需要去掉这些多余的东西

 

  解决办法:

  <table>中的修改

<!-- 现在的 -->
<td><fmt:formatDate value="${item.beginTime}"  pattern="yyyy-MM-dd"/></td>
<td><fmt:formatDate value="${item.finishTime}" pattern="yyyy-MM-dd"/></td>
<!-- 原来的 -->
<%-- <td>${item.beginTime}</td> --%>
<%-- <td>${item.finishTime}</td>  --%>

  日历控件中的修改

<div class="unit">
<label>开始时间:</label>
<input type="text" name="schoolCalendar.beginTime" value="<fmt:formatDate value='${schoolCalendar.beginTime}' pattern='yyyy-MM-dd'/>" class="date required" size="30" /><a class="inputDateButton" href="javascript:;">选择</a>
</div>
<div class="unit">
<label>结束时间:</label>
<input type="text" name="schoolCalendar.finishTime"  value="<fmt:formatDate value='${schoolCalendar.finishTime}' pattern='yyyy-MM-dd' />"  class="date required" size="30" /><a class="inputDateButton" href="javascript:;">选择</a>
</div>

   效果图:

  JSTL中的格式化还有数字等,以后在项目中用到会及时来更新博客与大家分享。

 

原文地址:https://www.cnblogs.com/jyh317/p/3533442.html