繁体   English   中英

如何更改LocalDate提供的月份的语言?

[英]How can I change the language of the months provided by LocalDate?

我需要找到当前月份并进行打印。 我有以下代码:

this.currentDate=LocalDate.now();
this.month = this.currentDate.getMonth();

问题是该月份是英文,我需要用法语打印,以与网站的其他语言匹配。 如何选择LocalDate.now()方法提供的月份语言,而无需每次显示时都需要手动翻译?

您可以使用DateTimeFormatter为法语创建格式器,如下所示:

final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, dd MMMM, yyyy", Locale.FRENCH);
final String month = LocalDate.now().format(formatter);

您可以使用getDisplayName()Month类型转换为String ,这可以将语言环境更改为法语,如下所示:

this.currentDate = LocalDate.now();
this.month = this.currentDate.getMonth().getDisplayName(TextStyle.FULL, Locale.FRANCE);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM