分享工作上用到的,根据年月获取月份!
Java获取方式 :
public static void main(String[] args) throws IOException, InterruptedException, JSONException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// 根据年,月获取最大天数的第一种方法
// 例如获取2月最大天数,传递月份时,应为3月 通过3月1的前一天来获取最大天数
Calendar calDate = Calendar.getInstance();
calDate.set(Calendar.YEAR, 2020);
calDate.set(Calendar.MONTH, 2);
calDate.set(Calendar.DATE, 0);
// 三月1号的前一天即2月份最大天数
int maxDate = calDate.get(Calendar.DATE);
calDate.set(calDate.get(Calendar.YEAR), calDate.get(Calendar.MONTH), maxDate);
// 根据年,月获取最大天数的第二种方法
// 例如获取2月最大天数,传递月份时,应为2月 通过getActualMaximum()方法获取最大天数
Calendar calDate1 = Calendar.getInstance();
calDate1.set(Calendar.YEAR, 2020);