lius
2023-07-12 650f5b86d2af51a0a3c7334703bdc2916a82a749
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/util/DateUtils.java
@@ -5,9 +5,15 @@
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class DateUtils {
@@ -28,6 +34,7 @@
        long d2 = d1.getTime() - 86400*1000;
        return new Date(d2);
    }
    /**
     * @return 返回时间差的语言描述  如1天2小时5分6秒
     */
@@ -155,6 +162,7 @@
    public static final String STR_DATE_TIME_FULL = "yyyyMMddHHmmssSSS";
    public static final String STR_HHMMSS = "HH:mm:ss";
    public static final String STR_HHMM = "HH:mm";
    /**
     * <p>
     * Description: 实际投标月份
@@ -207,8 +215,7 @@
     * Description: 修改时间为指定时间当天的23:59:59.000
     * </p>
     *
     * @param date
     *            需要修改的时间
     * @param date 需要修改的时间
     * @return 修改后的时间
     */
    public static Date fillTime(Date date) {
@@ -218,10 +225,8 @@
    }
    /**
     * @param date
     *            当前时间
     * @param i
     *            往前几天
     * @param date 当前时间
     * @param i    往前几天
     * @return
     */
    public static Date fillBeforeTime(Date date, Integer i) {
@@ -239,8 +244,7 @@
     * Description: 修改时间为指定时间前一天的00:00:00
     * </p>
     *
     * @param date
     *            需要修改的时间
     * @param date 需要修改的时间
     * @return 修改后的时间
     */
    public static Date plusTime(Date date, Integer i) {
@@ -257,8 +261,7 @@
     * </p>
     * 如: 2013-11-11 18:56:33 ---> 2013-11-11 00:00:00
     *
     * @param date
     *            需要修改的时间
     * @param date 需要修改的时间
     * @return 修改后的时间
     */
    public static Date removeTime(Date date) {
@@ -278,8 +281,7 @@
     * Description: 按默认格式(yyyy-MM-dd HH:mm:ss.SSS)获取时间字符串
     * </p>
     *
     * @param date
     *            要转换的日期
     * @param date 要转换的日期
     * @return 转换后的时间字符串
     */
    public static String format(Date date) {
@@ -303,15 +305,14 @@
        Date date=curr.getTime();
        return date;
    }
    /**
     * <p>
     * Description: 按指定格式获取时间字符串
     * </p>
     *
     * @param date
     *            要转换的日期
     * @param format
     *            格式,例如:yyyy-MM-dd HH:mm:ss.SSS
     * @param date   要转换的日期
     * @param format 格式,例如:yyyy-MM-dd HH:mm:ss.SSS
     * @return 转换后的时间字符串
     */
    public static String format(Date date, String format) {
@@ -324,8 +325,7 @@
     * Description: 加月函数
     * </p>
     *
     * @param month
     *            月份数
     * @param month 月份数
     * @return
     */
    public static Date addMonth(Integer month, Date time) {
@@ -400,6 +400,7 @@
        double hours = (t2 - t1) / (1000 * 60 * 60);
        return Double.valueOf(new DecimalFormat("#.00").format(hours));
    }
    //根据当前时间和出生日期获取年龄
    public static int getAge(Date birthDay){
        Calendar cal = Calendar.getInstance();
@@ -468,6 +469,7 @@
        }
        return null;
    }
    public static Date toDateMedium(String date){
        SimpleDateFormat df = new SimpleDateFormat(STR_DATE_TIME_SMALL);
        try {
@@ -477,6 +479,7 @@
            return null;
        }
    }
    public static Integer getDate(Date date) {
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
@@ -486,9 +489,11 @@
        }
        return null;
    }
    public static Integer getYear() {
        return getYear(new Date());
    }
    public static Integer getYear(Date date) {
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
@@ -498,9 +503,11 @@
        }
        return null;
    }
    public static Integer getMonth() {
        return getMonth(new Date());
    }
    public static Integer getMonth(Date date) {
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
@@ -510,9 +517,11 @@
        }
        return null;
    }
    public static Integer getDay() {
        return getDay(new Date());
    }
    public static Integer getDay(Date date) {
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
@@ -544,6 +553,7 @@
        dates[1] = endsTime;
        return dates;
    }
    public static Date[] getMonthStartTimeAndEndTime(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
@@ -570,6 +580,7 @@
    /**
     * 获取days天的时间区间,endTime 为当天的后一天0点,
     * startTime 为endTime前days天
     *
     * @param days
     * @return
     */
@@ -585,6 +596,7 @@
    /**
     * 根据某一年获取最后一天的时间
     * 2013 ---> 2013-12-31 23:59:59.000
     *
     * @param year
     * @return
     */
@@ -600,6 +612,7 @@
    /**
     * 获取start/end的所有日期字符串 格式yyyy-MM-dd
     *
     * @param start
     * @param end
     * @return
@@ -619,6 +632,7 @@
    /**
     * 获取start/end的所有日期字符串 格式yyyy-MM-dd
     *
     * @param start
     * @param end
     * @return
@@ -638,6 +652,7 @@
    /**
     * 获取start/end的所有日期字符串 格式yyyyMMdd
     *
     * @param start
     * @param end
     * @return
@@ -673,6 +688,7 @@
    /**
     * 获取dateStr的日期格式yyyy-MM-dd
     *
     * @param dateStr
     * @return
     */
@@ -688,6 +704,7 @@
    /**
     * 获取dateStr的日期格式yyyyMMdd
     *
     * @param dateStr
     * @return
     */
@@ -712,7 +729,6 @@
    }
    /**
     *
     * @param time
     * @param n
     * @return  在一个时间上加秒
@@ -725,7 +741,6 @@
    }
    /**
     *
     * @param time
     * @param n
     * @return  在一个时间上加分钟
@@ -738,7 +753,6 @@
    }
    /**
     *
     * @param time
     * @param n
     * @return  在一个时间上加小时
@@ -752,6 +766,7 @@
    /**
     * 获取start/end的所有日期字符串 格式yyyy-MM-dd
     *
     * @param start
     * @param end
     * @return
@@ -776,8 +791,10 @@
        }
        return list;
    }
    /**
     * 获取start/end的所有日期字符串 格式yyyy
     *
     * @param start
     * @param end
     * @return
@@ -802,10 +819,12 @@
        }
        return list;
    }
    /**
     * 获取当前时间 定位到小时
     * 格式为 yyyy-MM-dd hh:mm
     * 例:2018-02-27 11:00
     *
     * @return
     */
    public static Date getNowHourDate() {
@@ -822,6 +841,7 @@
    /**
     * 获取每日8:11或11:11的时间点
     *
     * @return
     */
    public static Date getNowHourDateTo() {
@@ -845,6 +865,7 @@
    /**
     * 获取每日8:00、13:00、20:00的时间点
     *
     * @return
     */
    public static List<Date> getHourDateList(Date time) {
@@ -857,6 +878,7 @@
    /**
     * 获取上月的最后一天
     *
     * @return
     */
    public static Date getPreviousMonthLastDay() {
@@ -867,6 +889,7 @@
    /**
     * 获取end时间月的第一天
     *
     * @param end 月份最后一天
     * @return
     */
@@ -882,8 +905,7 @@
        int hour = 0;
        if (time <= 0) {
            return "0小时";
        }
        else {
        } else {
            BigDecimal bigDecimal = new BigDecimal(time);
            BigDecimal bigDecimal1 = new BigDecimal(3600);
            BigDecimal hourBigDecimal = new BigDecimal(0);
@@ -924,6 +946,7 @@
            retStr = "" + i;
        return retStr;
    }
    /**
     * 验证时间
     *
@@ -962,11 +985,11 @@
    public static long getTimeWithOutDay(Date d) {
        return d.getTime()/1000%86400;
    }
    /**
     * @Description: long类型转换成日期
     *
     * @param lo 毫秒数
     * @return String yyyy-MM-dd HH:mm:ss
     * @Description: long类型转换成日期
     */
    public static String longToDate(long lo){
        Date date = new Date(lo);
@@ -975,12 +998,17 @@
    }
    /**
     *
     * @param startDate
     * @param endDate
     * @return
     */
    public static List<Date> getWeekDays(LocalDate startDate, LocalDate endDate) {
        return null;
        List<Date> result = new ArrayList<>();
        List<LocalDate> dateList = Stream.iterate(startDate, localDate -> localDate.plusDays(1))
                .limit(ChronoUnit.DAYS.between(startDate, endDate) + 1)
                .filter(localDate -> DayOfWeek.SATURDAY.equals(DayOfWeek.of(localDate.get(ChronoField.DAY_OF_WEEK))) || DayOfWeek.SUNDAY.equals(DayOfWeek.of(localDate.get(ChronoField.DAY_OF_WEEK))))
                .collect(Collectors.toList());
        dateList.forEach(localDate -> result.add(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));
        return result;
    }
}