Java – How to get a list of Month Names with Locale
程序员文章站
2022-04-24 22:25:59
...
package com.sheting.basic.utilities;
import java.text.DateFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
public class DisplayMonthNames {
// DateFormatSymbols in default Locale
private static final DateFormatSymbols dfs = new DateFormatSymbols();
// DateFormatSymbols in pre defined Locale
private static final DateFormatSymbols english_dfs = new DateFormatSymbols(Locale.ENGLISH);
public static void main(String... args) {
String[] months = dfs.getMonths();
System.out.printf("List of months: ");
System.out.println(Arrays.toString(months));
String[] shortMonths = dfs.getShortMonths();
System.out.printf("List of short months: ");
System.out.println(Arrays.toString(shortMonths));
String[] englishMonths = english_dfs.getMonths();
System.out.printf("List of english months: ");
System.out.println(Arrays.toString(englishMonths));
String[] englishShortMonths = english_dfs.getShortMonths();
System.out.printf("List of english short months: ");
System.out.println(Arrays.toString(englishShortMonths));
}
}
List of months: [一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月, ]
List of short months: [一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月, ]
List of english months: [January, February, March, April, May, June, July, August, September, October, November, December, ]
List of english short months: [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, ]
上一篇: 一个元素如何在父元素内水平垂直居中