Joe
Joe

Reputation: 1

How to display the current month in FTL code?

How can I print the current month in a ftl file?

Upvotes: 0

Views: 1785

Answers (3)

Brhane Abrham
Brhane Abrham

Reputation: 1

You can use this to get the current month.

<#assign currentMonth =  .now?string("MMMM") />

Upvotes: 0

Greg Case
Greg Case

Reputation: 3240

Assuming you have a configuration already, and you are doing something like this to process it:

Template template = config.getTemplate("template.ftl");
Map<String,Object> model = new HashMap<String,Object>();
model.put("currentDate", new Date());
StringWriter writer = new StringWriter();
template.process(model, writer);

You can reference your date in template.ftl by doing something like this:

Today's date is ${currentDate?string("MMMM")}!

The MMMM part can be any string using the SimpleDateFormat syntax

Upvotes: 1

Martijn Courteaux
Martijn Courteaux

Reputation: 68857

I really don't know (and cannot find directly) what FTL is, so please don't kill me if this is not what you want.

But: To get the current month you can use GregorianCalendar:

GregorianCalendar gc = new GregorianCalendar();
int month = gc.get(GregorianCalendar.MONTH);

Upvotes: 0

Related Questions