| | |
| | | * 日期格式(yyyy-MM-dd HH) |
| | | * */ |
| | | public static final String yyyy_MM_dd_HH_EN = "yyyy-MM-dd HH"; |
| | | /* |
| | | * 日期格式(MM-dd) |
| | | * */ |
| | | public static final String MM_dd_EN = "MM-dd"; |
| | | |
| | | /* |
| | | * Date类toString格式 |
| | |
| | | return dateToDateString(now.getTime(), formatStr); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取指定日期day天后的一个(formatStr)的字符串 |
| | | * |
| | | * @param date |
| | | * @param date, |
| | | * @param hours |
| | | * @return |
| | | */ |
| | | public static Date getDateAddHour(Date date,int hours) { |
| | | Calendar now = Calendar.getInstance(TimeZone.getDefault()); |
| | | now.setTime(date); |
| | | now.add(Calendar.HOUR_OF_DAY, hours); |
| | | return now.getTime(); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 获取指定日期day天后的日期 |
| | | * @Param: [date, day] |
| | |
| | | } |
| | | return new Date(); |
| | | } |
| | | |
| | | |
| | | |
| | | public static String getAfterNDays(Date date, int n, String formateStr) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat(formateStr); |
| | |
| | | int year = cal.get(Calendar.YEAR); |
| | | return year == currentYear; |
| | | } |
| | | |
| | | /* |
| | | * 判断日期是否为本月 |
| | | * */ |
| | | public static boolean isCurrentMonth(Date date) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(new Date()); |
| | | int currentYear = cal.get(Calendar.MONTH); |
| | | cal.setTime(date); |
| | | int year = cal.get(Calendar.MONTH); |
| | | return year == currentYear; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取当前月的最后一天 |
| | |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | //加减年份 |
| | | public static Date addYears(Date date, int years) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.add(Calendar.YEAR, years); |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | /** |
| | | * <p> |
| | | * Title: getDays |