java 获取当月第一天和最后一天

//获取当前月第一天:
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH, 1);//设置为1,当前日期既为本月第一天
String monthfirst = format.format(c.getTime());
System.out.println("===============nowfirst:" + monthfirst);

//获取当前月最后一天
Calendar ca = Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
String monthlast = format.format(ca.getTime());
System.out.println("===============last:" + monthlast);

你可能感兴趣的:(java,calender,java)