查表法解决calendar中月份及星期初始值为0的情况。

时间:2024-03-01 21:41:15

 Calendar ca = Calendar.getInstance();

String [] index = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};

String [] index1= {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};

 

String week = index[ca.get(Calendar.WEEK_OF_MONTH)];

String month = index1[ca.get(Calendar.MONTH)];

System.out.println(ca.get(Calendar.YEAR)+"年"+month+ca.get(Calendar.DAY_OF_MONTH)+"日"+week);