Java如何以短格式显示月份?

在Java中,如何显示短格式的月份名称?

使用DateFormatSymbols().DateFormatSymbols类的getShortMonths()方法,本示例显示了几个月的简写名称。

package com.yiibai;

import java.text.SimpleDateFormat; import java.text.DateFormatSymbols; public class DisplayingMonthsShortFormat { public static void main(String[] args) { String[] shortMonths = new DateFormatSymbols().getShortMonths(); for (int i = 0; i < (shortMonths.length - 1); i++) { String shortMonth = shortMonths[i]; System.out.println("shortMonth = " + shortMonth); } } } 
Java

上述代码示例将产生以下结果,结果将根据当前系统时间而有变化。

shortMonth = 一月
shortMonth = 二月
shortMonth = 三月
shortMonth = 四月
shortMonth = 五月
shortMonth = 六月
shortMonth = 七月
shortMonth = 八月
shortMonth = 九月
shortMonth = 十月
shortMonth = 十一月
shortMonth = 十二月
Shell

以下是日期,时间和短时间的另一个示例。

package com.yiibai;

import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.Calendar; public class DisplayingMonthsShortFormat2 { public static void main(String[] argv) throws Exception { String str1 = "yyyy-MM-dd"; Date d = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat(str1, Locale.FRENCH); System.out.println(sdf.format(d)); sdf = new SimpleDateFormat(str1, Locale.ENGLISH); System.out.println(sdf.format(d)); } } 
Java

上述代码示例将产生以下结果(结果取决于当前日期)。

2017-09-17
2017-09-17

转载于:https://www.cnblogs.com/borter/p/9613410.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值