Java – How to get a list of Month Names with Locale

本文展示了一个Java程序,用于打印默认区域设置及英语区域设置下的完整和缩写月份名称。通过使用`DateFormatSymbols`类,我们可以获取不同语言环境中月份的具体表示形式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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, ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值