velocity 页面时间显示,时间格式转换

有时候我们从数据库中读取出来的时间字段在页面上显示的并不是我们想要的效果,如图:
 
 

这里我们就需要做转换,页面技术使用的是velocity,方法如下:
 
1、在toolbox.xml配置文件中添加以下代码:
<tool>
   <key>dateTool</key>
   <scope>application</scope>
   <class>org.apache.velocity.tools.generic.DateTool</class>
</tool>


2、在前台页面中需要显示时间的地方添加这样的代码:
 
<td>$!dateTool.format('FULL',$!list.createTime)</td>
<td>$!dateTool.format('yyyy-MM-dd HH:mm:ss',$!list.sendTime)</td> 
注意:$!dateToole.format()  必须和配置文件中的<key></key>标签中的值一致
 
最后效果如下:
 
 
 
 更过格式可以参考官网:

 
 
 
 
 
 
 
 
 
 
 
 
 
posted @ 2015-01-25 14:15  Admol  阅读(4068)  评论(0编辑  收藏  举报