liujie
2023-10-26 e030255c23c7ba3e2cbad1036a810d6d72fa864f
cloud-server-account/src/main/java/com/dsh/account/util/DateTimeHelper.java
@@ -2,9 +2,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.*;
import java.util.*;
@@ -244,7 +242,6 @@
        try {
            return parseToDate(formatDateTimetoString(getSystemDate(), fmtstr));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return getSystemDate();
        }
@@ -1350,6 +1347,52 @@
    }
    /**
     * 获取指定月份开始时0点0分0秒
     * @param input 输入的时间,"yyyy-MM"
     * @return
     */
    public static Date getCurrentIdetMouthStart(String input) {
        // 解析年月字符串
        YearMonth yearMonth = YearMonth.parse(input);
        // 获取月份的开始时间(月初0点)
        LocalDate startOfMonth = yearMonth.atDay(1);
        LocalDateTime startDateTime = startOfMonth.atTime(LocalTime.MIN);
        return Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
    /**
     * 获取当月结束时23点59分59秒
     *
     * @return
     */
    public static Date getCurrentMouthEnd() {
        Date d = getSystemDate();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        calendar.set(Calendar.DAY_OF_MONTH, lastDay);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }
    /**
     * 获取指定月份结束时23点59分59秒
     * @param input 输入的时间,"yyyy-MM"
     * @return
     */
    public static Date getCurrentIdeaMouthEnd(String input) {
        // 解析年月字符串
        YearMonth yearMonth = YearMonth.parse(input);
        // 获取月份的结束时间(月末23:59:59秒)
        LocalDate endOfMonth = yearMonth.atEndOfMonth();
        LocalDateTime endDateTime = endOfMonth.atTime(23, 59, 59);
        return Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
    /**
     * 返回下月的这天
     *
     * @param date
@@ -1440,6 +1483,23 @@
    }
    /**
     * 获取当前日期是星期几<br>
     * Obtain the day of the week for the current date.
     * @param dt
     * @return 当前日期是星期几
     */
    public static int getWeekNumOfDate(Date dt) {
        Integer[] weekDays = {7, 1, 2, 3, 4, 5, 6}; // 将周一的数值设为2,依次递增表示周二到周日
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0) {
            w = 6; // 如果为负数,将其设为6,表示周日
        }
        return weekDays[w];
    }
    /**
     * 获取今天时间 2017-11-20 00:00:00
     */
    public static Date todayDate() {