Java显示短格式的月份名称
如何显示短格式的月份名称?
解决方法
本示例显示月份短格式的名称使用DateFormatSymbols类的DateFormatSymbols().getShortMonths() 方法。
import java.text.SimpleDateFormat; import java.text.DateFormatSymbols; public class Main { 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); } } }
结果
上面的代码示例将产生以下结果。
shortMonth = Jan shortMonth = Feb shortMonth = Mar shortMonth = Apr shortMonth = May shortMonth = Jun shortMonth = Jul shortMonth = Aug shortMonth = Sep shortMonth = Oct shortMonth = Nov shortMonth = Dec