| | |
| | | } |
| | | |
| | | /* |
| | | * 获取指定日期月的第一天 |
| | | * */ |
| | | public static Date getFirstDayOfMonth(Date date){ |
| | | final Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(date); |
| | | final int last = cal.getActualMinimum(Calendar.DAY_OF_MONTH); |
| | | cal.set(Calendar.DAY_OF_MONTH, last); |
| | | cal.set(Calendar.HOUR_OF_DAY,0); |
| | | cal.set(Calendar.MINUTE,0); |
| | | cal.set(Calendar.SECOND,0); |
| | | return cal.getTime(); |
| | | } |
| | | |
| | | /* |
| | | * 获取指定日期月的最后一天 |
| | | * */ |
| | | public static Date getLastDayOfMonth(Date date) { |
| | | final Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(date); |
| | | final int last = cal.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | cal.set(Calendar.DAY_OF_YEAR, last); |
| | | cal.set(Calendar.HOUR_OF_DAY, 23); |
| | | cal.set(Calendar.MINUTE, 59); |
| | | cal.set(Calendar.SECOND, 59); |
| | | return cal.getTime(); |
| | | } |
| | | |
| | | |
| | | /* |
| | | * 判断日期是否为今年 |
| | | * */ |
| | | public static boolean isCurrentYear(Date date) { |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | return date; |
| | | } |
| | | |
| | | /** |
| | | * 获取指定年月的第一天 |
| | | * |
| | | * @param year |
| | | * @param month |
| | | * @return |
| | | */ |
| | | public static String getFirstDayOfMonth(int year, int month) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | // 设置年份 |
| | | cal.set(Calendar.YEAR, year); |
| | | // 设置月份 |
| | | cal.set(Calendar.MONTH, month - 1); |
| | | // 获取某月最小天数 |
| | | int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH); |
| | | // 设置日历中月份的最大天数 |
| | | cal.set(Calendar.DAY_OF_MONTH, lastDay); |
| | | // 格式化日期 |
| | | DateFormat df = getDateFormat(yyyy_MM_dd_EN); |
| | | return df.format(cal.getTime()); |
| | | } |
| | | |
| | | /** |
| | | * 获取指定年月的第一天 |
| | | * |
| | | * @param year |
| | | * @param month |
| | | * @return |
| | | */ |
| | | public static String getLastDayOfMonth(int year, int month) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | // 设置年份 |
| | | cal.set(Calendar.YEAR, year); |
| | | // 设置月份 |
| | | cal.set(Calendar.MONTH, month - 1); |
| | | // 获取某月最大天数 |
| | | int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | // 设置日历中月份的最大天数 |
| | | cal.set(Calendar.DAY_OF_MONTH, lastDay); |
| | | // 格式化日期 |
| | | DateFormat df = getDateFormat(yyyy_MM_dd_EN); |
| | | return df.format(cal.getTime()); |
| | | } |
| | | |
| | | /** |