gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:48:29 24 4
gpt4 key购买 nike

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

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

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

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

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"

非常感谢任何帮助!

最佳答案

您可以使用 velocity 的 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(....)

关于java - 在 Velocity 文件中将日期格式化为葡萄牙语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48624712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com