Freemarker在模板中打印日期 [英] Freemarker print date in template

查看:197
本文介绍了Freemarker在模板中打印日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印模板激活时的当前日期。我已经看到,我必须将一个新的Date()Java对象传递给模板,但是我不知道该怎么做,或者将其放在代码中。



在这种情况下,有人知道如何将Java对象传递给模板?



谢谢!!

解决方案

实际上,您不必将新的Date()传递给您的模板,因为将时间戳放入模板输出是相当普遍的,因此FreeMarker提供了特殊变量,称为 .now 返回当前日期和时间。您可以在这样的模板中使用它:

 页面生成:$ {。now} 

(FreeMarker还包含不同的内置格式化日期: http://freemarker.org/docs/ref_builtins_date.html



更新:仅适用于最新版本的FreeMarker, 2.3.17


I am trying to print the current date when the template is activated. I have read that I have to pass a new Date() Java object to the template, but I don't know how to do that or where to put it in the code.

Does someone know how to pass a Java object to the template in this case?

Thank you !!

解决方案

Actually you don't have to pass a new Date() to your template, because placing a timestamp into a template's output is quite common and therefore FreeMarker provides a special variable called .now which returns the current date and time. You can use it in your template like this:

Page generated: ${.now}

(FreeMarker also contains different built-ins for formatting dates: http://freemarker.org/docs/ref_builtins_date.html)

Update: Works only with the latest version of FreeMarker, 2.3.17.

这篇关于Freemarker在模板中打印日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆