在 Velocity 文件中将日期格式化为葡萄牙语

Format date to Portuguese in Velocity file

我有一个 Web 应用程序可以发送一封电子邮件,其中包含有关事件的详细信息。该电子邮件使用由 Java 后端发送的 Velocity 模板。此应用程序托管在位于巴西的 Tomcat 服务器上。

当电子邮件中包含活动日期时,我会看到以下内容

Data e Horário da Conferência (Conference Date):  Mon Feb 05 10:45:00 BRST 2018

由于应用程序托管在巴西,date/time 和时区是正确的,但是我想像这样打印日期:

Data e Horário da Conferência (Conference Date):  Seg 05 Fev 10:45:00 BRST 2018

注意日期和月份的拼写。

有没有办法在 Velocity 文件或 Java 中实现此目的?或者我是否需要更改某些 Tomcat 设置?

示例:

-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Duser.country=BR -Duser.language=pt"

非常感谢任何帮助!

您可以使用速度的 DateTool,它是 velocity tools (jar)

的一部分

The methods of this tool are highly interconnected, and overriding key methods provides an easy way to create subclasses that use a non-default format, calendar, locale, or timezone.

将其添加到速度上下文中:

context.put("date", new DateTool());

然后使用toDate/format函数

format(String format, Object obj, Locale locale) Converts the specified object to a date and returns a formatted string representing that date in the specified Locale.

$date.format(....)