欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

velocity 调用自定义方法,日期函数为例 博客分类: velocity 乔乐共享velocityxmlfunctiondate 

程序员文章站 2024-03-26 13:12:17
...
toolbox.xml
<tool>
		<key>dateUtil</key>
		<scope>application</scope>
		<class>com.anxin.msapweb.util.DateUtil</class>
	</tool>


$!{dateUtil.getCurrDate_YYYY_MM_DD()}


日期函数
<tools>
   <toolbox scope="application">
     <tool class="org.apache.velocity.tools.generic.DateTool"
              format="yyyy-MM-dd"/>
   </toolbox>
 </tools>


注:若不可以添加()
Example of formatting the "current" date:
  $date                         -> Oct 19, 2003 9:54:50 PM
  $date.long                    -> October 19, 2003 9:54:50 PM PDT
  $date.medium_time             -> 9:54:50 PM
  $date.full_date               -> Sunday, October 19, 2003
  $date.get('default','short')  -> Oct 19, 2003 9:54 PM
  $date.get('yyyy-M-d H:m:s')   -> 2003-10-19 21:54:50

Example of formatting an arbitrary date:
  $myDate                        -> Tue Oct 07 03:14:50 PDT 2003
  $date.format('medium',$myDate) -> Oct 7, 2003 3:14:50 AM