2018-05-19---Calendar应用

贺俊楚
2023-12-01
SimpleDateFormat simple= new SimpleDateFormat("yyyy-MM-dd");
String firstDay, lastDay;
Calendar cal = null;
cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 0);//当前月
cal.set(Calendar.DAY_OF_MONTH, 1);//当前月第一天
firstDay = simple.format(cal.getTime());//当前年当前月第一天

cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 1);//下个月
cal.set(Calendar.DAY_OF_MONTH, 0);//当前月最后一天
lastDay = simple.format(cal.getTime());//当前年当前月最后一天


Calendar cal = Calendar.getInstance();
cal.get(Calendar.YEAR);//当前年
cal.get(Calendar.MONTH)+1;//当前月
cal.get(Calendar.DATE);//当前日
 类似资料: