如何在 Java 中将整数转换为本地化的月份名称? [英] How can I convert an Integer to localized month name in Java?
本文介绍了如何在 Java 中将整数转换为本地化的月份名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到一个整数,我需要在各种语言环境中转换为月份名称:
I get an integer and I need to convert to a month names in various locales:
locale en-us 示例:
1 -> 一月
2 -> 二月
Example for locale en-us:
1 -> January
2 -> February
区域设置 es-mx 的示例:
1 -> 埃内罗
2 -> 费布雷罗
Example for locale es-mx:
1 -> Enero
2 -> Febrero
推荐答案
import java.text.DateFormatSymbols;
public String getMonth(int month) {
return new DateFormatSymbols().getMonths()[month-1];
}
这篇关于如何在 Java 中将整数转换为本地化的月份名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文