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