时间:2021-07-01 10:21:17 帮助过:52人阅读
$dateformat.format("yyyy-MM-dd",$date)
//2 Create a Context object
VelocityContext context = newVelocityContext();
//3 Add you data object to this context
context.put("date", new Date());
//扩展功能,提供一个日期格式工具类,在模板中调用其方法即可。
context.put("dateformat", newDateUtils());
//4 Choose a template
Template template =Velocity.getTemplate("formatedate.vm");
//5 Merge the template and you data toproduce the output
StringWriter sw = new StringWriter();
template.merge(context, sw);
sw.flush();
System.out.println(sw.toString());
formatedate.vm
${date}
===
$date
===
$dateformat.format("yyyy-MM-dd",$date)
-==
$dateformat.format("yyyy-MM-ddHH:mm:ss",$date)
==
$dateformat.format("yyyyMMdd",$date)以上就是velocity第9个应用例子 ---格式化日期的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!