How to get the current year from freemarker template

Anna picture Anna · May 22, 2017 · Viewed 7.7k times · Source

I have use the ${.now} to get the current time stamp inside the freemarker templates, but I want to know how can I get only the year?

Answer

ddekany picture ddekany · May 22, 2017

Like ${.now?string('yyyy')}. (Note that this will return a string, which is what you want if you only want to print it. If by any chance you need a number, so that you can do arithmetic with it, then it's .now?string('yyyy')?number.)