如何在 ftl 文件中打印当前月份?
1476 次
3 回答
1
假设你已经有一个配置,并且你正在做这样的事情来处理它:
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);
您可以通过执行以下操作在 template.ftl 中引用您的日期:
Today's date is ${currentDate?string("MMMM")}!
该MMMM
部分可以是使用 SimpleDateFormat 语法的任何字符串
于 2010-05-12T14:39:07.283 回答
0
我真的不知道(也无法直接找到)FTL 是什么,所以如果这不是你想要的,请不要杀了我。
但是:要获取当前月份,您可以使用 GregorianCalendar:
GregorianCalendar gc = new GregorianCalendar();
int month = gc.get(GregorianCalendar.MONTH);
于 2010-05-11T18:31:30.640 回答
0
您可以使用它来获取当前月份。
<#assign currentMonth = .now?string("MMMM") />
于 2021-01-28T15:09:00.663 回答