/** * 得到本月的第一天 */ public static String getMonthFirstDay() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, calendar .getActualMinimum(Calendar.DAY_OF_MONTH)); // calendar.set( Calendar.DATE, 1); SimpleDateFormat simpleFormate = new SimpleDateFormat("yyyy-MM-dd"); return simpleFormate.format(calendar.getTime()); } /** * 得到本月的最后一天 */ public static String getMonthLastDay() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, calendar .getActualMaximum(Calendar.DAY_OF_MONTH));// calendar.set( Calendar.DATE, 1);// calendar.roll(Calendar.DATE, - 1); SimpleDateFormat simpleFormate = new SimpleDateFormat("yyyy-MM-dd"); return simpleFormate.format(calendar.getTime()); }
获取某月的第一天和最后一天的日期
Calendar ca = Calendar.getInstance();ca.setTime(someDate); // someDate 为你要获取的那个月的时间ca.set(Calendar.DAY_OF_MONTH, 1);//第一天Date firstDate = ca.getTime();ca.add(Calendar.MONTH, 1);ca.add(Calendar.DAY_OF_MONTH, -1);//最后一天Date lastDate = ca.getTime();