hsz
hsz

Reputation: 152226

Current date in ftl template

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

Upvotes: 3

Views: 5515

Answers (2)

MatBanik
MatBanik

Reputation: 26860

Tying up to the above answer: Once you place date object into your model you do this:

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

see freemarker doc

Upvotes: 2

Christopher Klewes
Christopher Klewes

Reputation: 11435

Freemarker is a templating library, there isn't a today variable, you should consider passing a new Date() Java Object to the template, and format it. Consider to create a wrapper class for this, to generate the new Date() exactly at the time it is called.

Upvotes: 2

Related Questions