views:

91

answers:

2

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

A: 

Hi,
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);
Martijn Courteaux
+1  A: 

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

gregcase