chenjiahe
2022-12-16 5bfcd30741d716cb46bb4540051c3bed65737189
新增时间算法
1个文件已修改
43 ■■■■■ 已修改文件
src/main/java/com/hx/util/DateUtil.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/util/DateUtil.java
@@ -603,6 +603,22 @@
        return sdf.format(calendar.getTime());
    }
    /**
     * 获取当前年的开始时间
     * @param time 时间
     * @return 返回时间 格式yyyy-MM-dd 00:00:00
     */
    public static Date getYearStart(Date time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        calendar.set(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }
    /**
     * 日期2000-01-01变2000-01-01 00:00:00
@@ -628,6 +644,18 @@
        calendar.set(Calendar.SECOND, 59);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        return sdf.format(calendar.getTime());
    }
    /**
     * 日期2000-01-01变2000-01-01 23:59:59
     */
    public static Date dayToEndDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }
    /**获取月份的天数
@@ -671,4 +699,19 @@
        calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }
    /**当天多少点前
     * @param date 时间
     * @param num 多少点前,不含当点前,24小时制
     * @return 月份的天数
     */
    public static boolean getFrontMinute(Date date,int num) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR, num-1);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        return date.compareTo(cal.getTime()) < 1;
    }
}