- public static String getLastDayOfMonth(int year, int month) {
- Calendar cal = Calendar.getInstance();
- cal.set(Calendar.YEAR, year);
- cal.set(Calendar.MONTH, month-1);
- cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DATE));
- return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
- }
- public static String getFirstDayOfMonth(int year, int month) {
- Calendar cal = Calendar.getInstance();
- cal.set(Calendar.YEAR, year);
- cal.set(Calendar.MONTH, month-1);
- cal.set(Calendar.DAY_OF_MONTH,cal.getMinimum(Calendar.DATE));
- return new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
- }
-
- //需要注意的是:月份是从0开始的,比如说如果输入5的话,实际上显示的是4月份的最后一天,所以月份减去1了
根据年和月,取月份的最后一天和月份的第一天
最新推荐文章于 2024-06-25 10:48:29 发布