Freemarker print date in template

前端 未结 3 1958
难免孤独
难免孤独 2021-02-08 10:10

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

3条回答
  •  野的像风
    2021-02-08 10:14

    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.

提交回复
热议问题