Current date in ftl template

Is it possible to print the current date in the specified format ( Y-m-d H:i:s) in ftl (FreeMarker)? I want to avoid the transition date from the controller to view.

+3
source share
2 answers

Freemarker is a template library, today's variable does not exist, you should consider passing the new Date()Java Object to the template and formatting it. Consider creating a wrapper class for this to create a new Date () exactly at the time you call it.

+2
source

Binding to the answer above: after you have placed the date object in your model, do the following:

 date?string("yy-MM-dd HH:mm:ss")

see freemarker doc

+2
source

Source: https://habr.com/ru/post/1796278/


All Articles