maven
5 天以前 9aec7c5d4e11dcd66f0c886c759bbaa54efe6211
src/main/java/com/ruoyi/common/utils/DateUtils.java
@@ -43,6 +43,15 @@
        return new Date();
    }
    public static LocalDate toLocalDate(Date date){
        if(date == null) return LocalDate.now();
        // 2. 指定固定时区转换(如东八区UTC+8、UTC零时区)
        return date.toInstant()
                .atZone(ZoneId.of("Asia/Shanghai")) // 东八区(北京/上海时区)
                // .atZone(ZoneId.of("UTC")) // 可选:UTC零时区
                .toLocalDate();
    }
    /**
     * 获取当前日期, 默认格式为yyyy-MM-dd
     * 
@@ -145,16 +154,20 @@
    }
    /**
     * 计算两个时间差
     * 计算时间差
     *
     * @param endDate 最后时间
     * @param startTime 开始时间
     * @return 时间差(天/小时/分钟)
     */
    public static String getDatePoor(Date endDate, Date nowDate)
    public static String timeDistance(Date endDate, Date startTime)
    {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        long diff = endDate.getTime() - startTime.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时