如何从日历获取月份名称 [英] How to get month name from Calendar

查看:144
本文介绍了如何从日历获取月份名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们知道 int monthNumber = calendar.get(Calendar.MONTH)时,是否有一个oneliner获取月份的名称?

Is there a oneliner to get the name of the month when we know int monthNumber = calendar.get(Calendar.MONTH) ? Or what is the easiest way?

推荐答案

也会这样。

  String getMonthForInt(int num) {
        String month = "wrong";
        DateFormatSymbols dfs = new DateFormatSymbols();
        String[] months = dfs.getMonths();
        if (num >= 0 && num <= 11 ) {
            month = months[num];
        }
        return month;
    }

这篇关于如何从日历获取月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆