package com.bonus.common.core.utils;

import lombok.extern.slf4j.Slf4j;

import java.text.*;
import java.time.*;
import java.util.*;

import static org.apache.commons.lang3.time.DateUtils.parseDate;


/**
 * @author HeiZi
 */
@Slf4j
public class DateTimeHelper {


    private static String[] parsePatterns = {
            "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
            "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
            "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};

    public static String format(Date d, String f) {
        SimpleDateFormat df = new SimpleDateFormat(f, Locale.US);
        return df.format(d);
    }

    public static boolean compareMonth(String time, String now) {
        try {
            int year = Integer.parseInt(time.split("-")[0].trim());
            int month = Integer.parseInt(time.split("-")[1].trim());
            int year1 = Integer.parseInt(now.split("-")[0].trim());
            int month1 = Integer.parseInt(now.split("-")[1].trim());
            if (year > year1) {
                return false;
            }
            if (year == year1) {
                if (month >= month1) {
                    return false;
                }
            }
            return true;

        } catch (Exception e) {
            log.error(e.toString(), e);
        }
        return false;
    }

    /**
     * 增加 LocalDateTime ==> Date
     */
    public static Date toDate(LocalDateTime temporalAccessor) {
        ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
        return Date.from(zdt.toInstant());
    }

    /**
     * 增加 LocalDate ==> Date
     */
    public static Date toDate(LocalDate temporalAccessor) {
        LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
        ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
        return Date.from(zdt.toInstant());
    }


    public static String dateTimeNow() {
        return dateTimeNow("yyyyMMddHHmmss");
    }


    public static String dateTimeNow(final String format) {
        return parseDateToStr(format, new Date());
    }

    public static String parseDateToStr(final String format, final Date date) {
        return new SimpleDateFormat(format).format(date);
    }


    /**
     * 日期型字符串转化为日期 格式
     */
    public static Date parseDates(Object str) {
        if (str == null) {
            return null;
        }
        try {
            return parseDate(str.toString(), parsePatterns);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getNowTime() {
        return format(new Date(), "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 获取当前时间的年份
     *
     * @return
     */
    public static String getNowYear() {
        return format(new Date(), "yyyy");
    }


    /**
     * 获取当前月份
     *
     * @return
     */
    public static String getNowMonths() {
        return format(new Date(), "MM");
    }

    /**
     * 获取当前小时
     *
     * @return
     */
    public static String getNowHours() {
        return format(new Date(), "HH");
    }


    public static String getNowYmd() {
        return new SimpleDateFormat("yyyyMMdd").format(new Date());
    }


    public static String getNowDay() {
        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    }

    public static String getTimesUpDown(String time) {
        try {
            if (StringHelper.isEmpty(time)) {
                return time;
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(time);
            // 创建Calendar对象，表示当前时间
            Calendar calendar = Calendar.getInstance();
            // 将Calendar对象设置为当前时间
            calendar.setTime(date);
            // 将时间减去5分钟
            calendar.add(Calendar.MINUTE, -5);
            calendar.add(Calendar.SECOND, -13);
            // 获取减去5分钟后的时间
            Date newTime = calendar.getTime();
            return sdf.format(newTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    public static String getNextDay() {
        Calendar calendar = Calendar.getInstance();
        // 对日期进行加1天的操作
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        // 获取明天的年、月、日
        int year = calendar.get(Calendar.YEAR);
        // 注意：月份从0开始计算
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        return year + "-" + month + "-" + day;
    }


    public static String getHouDay() {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        // 把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(Calendar.DATE, 1);
        // 这个时间就是日期往后推一天的结果
        date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    @SuppressWarnings("static-access")
    public static String getYesTodayt() {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        // 把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(calendar.DATE, -1);
        date = calendar.getTime();
        // 这个时间就是日期往后推一天的结果
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    @SuppressWarnings("static-access")
    public static String getQtDay() {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        // 把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(calendar.DATE, -2);
        // 这个时间就是日期往后推一天的结果
        date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }


    public static String format(String str, String format, String disFormat) {
        Date d = parse(str, format);
        return format(d, disFormat);
    }

    /**
     * 格式化 时间
     *
     * @param format
     * @return
     */
    public static String format(Date d, DateFormat format) {
        return format.format(d);
    }

    /**
     * 格式化 时间
     *
     * @param format
     * @return Date
     * @throws ParseException
     */
    public static Date parse(String dateStr, String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        try {
            return df.parse(dateStr);
        } catch (ParseException e) {
            return new Date();
        }
    }

    public static Date parse(String dateStr, String format, Date d) {
        try {
            SimpleDateFormat df = new SimpleDateFormat(format);
            return df.parse(dateStr);
        } catch (Exception e) {
            return d;
        }
    }

    /**
     * 解析时间
     *
     * @return Date
     * @throws ParseException
     */
    public static Date parse(String dateStr, DateFormat format) throws ParseException {
        return format.parse(dateStr);
    }

    /**
     * 获取当前时间的年月
     *
     * @return
     */
    public static String getPrevMonth() {
        return minusMonth(new Date(), 1);
    }

    /**
     * 获取当前时间的上个年月
     *
     * @return
     */
    public static String getNowMonth() {
        return format(new Date(), "yyyy-MM");
    }

    /**
     * 获取当前时间的年月日
     *
     * @return
     */
    public static String getNowDate() {
        return format(new Date(), "yyyy-MM-dd");
    }

    /**
     * @return
     */
    public static String minusMonth(Date date, int c) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.MONTH, -c);
            return format(cal.getTime(), df);
        } catch (Exception e) {
            return format(date, df);
        }
    }

    /**
     * @param month
     * @return
     */
    public static String minusMonth(String month, int c) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
            Date date = parse(month, df);

            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.MONTH, -c);

            return format(cal.getTime(), df);
        } catch (Exception e) {
            return month;
        }
    }

    /**
     * @return
     */
    public static Date minus(Date d, int type, int c) {
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            cal.add(type, -c);
            return cal.getTime();
        } catch (Exception e) {
            return new Date();
        }
    }

    private static String[] digits = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};

    public static String getWeekTimes(String time) {
        try {
            int month = Integer.parseInt(time.split("-")[1].trim());
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date date = df.parse(time);
            Calendar cal = Calendar.getInstance();
            cal.setFirstDayOfWeek(Calendar.MONDAY);
            cal.setTime(date);
            int weekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);
            String msg = digits[weekOfMonth];
            return month + "月" + msg + "周";
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
        return null;
    }


    public static String getAddMonth(String time, int num) {
        try {
            Integer year = Integer.parseInt(time.split("-")[0].trim());
            Integer month = Integer.parseInt(time.split("-")[1].trim());
            YearMonth yearMonth = YearMonth.of(year, month);
            YearMonth addedMonth = yearMonth.plusMonths(1);
            return addedMonth.toString();
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
        return null;

    }

    /**
     * 获取七周日期
     *
     * @return
     */
    public static List<String> getWeekList() {
        List<String> list = new ArrayList<>();
        String time = DateTimeHelper.getNowDay();
        int max = 6;
        for (int i = max; i >= 1; i--) {
            String timess = getDayAddOrReduce(time, -7 * i);
            list.add(timess);
        }
        list.add(time);
        return list;
    }


    /**
     * 得到前一个月
     *
     * @param month
     * @return
     */
    public static String prevMonth(String month) {
        return minusMonth(month, 1);
    }

    /**
     * 得到前一个月
     *
     * @param month
     * @return
     */
    public static String prevMonth(String month, int c) {
        return minusMonth(month, c);
    }

    public static float duration(String startTime, String stopTime) {
        Date sd = DateTimeHelper.parse(startTime, "yyyy-MM-dd HH:mm");
        long sl = sd.getTime();

        Date ed = DateTimeHelper.parse(stopTime, "yyyy-MM-dd HH:mm");
        long el = ed.getTime();

        float l = el - sl;
        if (l <= 0) {
            l = 0;
        }
        l = l / (1000 * 60);
        return l;
    }

    public static String getStartYearMonthBySeason(String year, int season) {
        switch (season) {
            case 1:
                return getYearMonth(year, "01");
            case 2:
                return getYearMonth(year, "04");
            case 3:
                return getYearMonth(year, "07");
            case 4:
                return getYearMonth(year, "10");
            default:
                return getYearMonth(year, "01");
        }
    }

    private static String getYearMonth(String year, String month) {
        return year + "-" + month;
    }

    public static String getEndYearMonthBySeason(String year, int season) {
        switch (season) {
            case 1:
                return getYearMonth(year, "03");
            case 2:
                return getYearMonth(year, "06");
            case 3:
                return getYearMonth(year, "09");
            case 4:
                return getYearMonth(year, "12");
            default:
                return getYearMonth(year, "03");
        }
    }

    /**
     * 获取本周的时间段 本周一至本周日
     *
     * @return
     */
    public static String getCurrentWeekTime() {
        String result = "";
        String currentDay = getNowDay();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        Date time;
        try {
            time = sdf.parse(currentDay);
            cal.setTime(time);
            System.out.println("要计算日期为:" + sdf.format(cal.getTime()));

            //判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了//获得当前日期是一个星期的第几天
            int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
            if (1 == dayWeek) {
                cal.add(Calendar.DAY_OF_MONTH, -1);
            }
            //设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
            cal.setFirstDayOfWeek(Calendar.MONDAY);
            //获得当前日期是一个星期的第几天
            int day = cal.get(Calendar.DAY_OF_WEEK);
            //根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
            cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
            System.out.println("所在周一的日期：" + sdf.format(cal.getTime()));
            result += sdf.format(cal.getTime());
            System.out.println(cal.getFirstDayOfWeek() + "-" + day + "+6=" + (cal.getFirstDayOfWeek() - day + 6));

            cal.add(Calendar.DATE, 6);
            result += "," + sdf.format(cal.getTime());
            System.out.println("所在下周日的日期：" + sdf.format(cal.getTime()));
            return result;

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取下周的开始时间和结束时间
     *
     * @return
     */
    public static String getNextWeekTime() {
        Date date = getBeginDayOfWeek();
        String time = format(date, "yyyy-MM-dd");
        Date date2 = getEndDayOfWeek();
        String time2 = format(date2, "yyyy-MM-dd");

        return time + "," + time2;
    }

    public static Date getBeginDayOfWeek() {
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
        cal.add(Calendar.WEEK_OF_MONTH, 1);
        if (dayofweek == 1) {
            dayofweek += 7;
        }
        cal.add(Calendar.DATE, 2 - dayofweek);
        return cal.getTime();
    }

    /**
     * 获取前一周的开始和结束时间
     *
     * @return
     */
    public static String getPrevWeek() {
        Date date = getBeginDayOfPrevWeek();
        String time = format(date, "yyyy-MM-dd");
        Date date2 = getEndDayOfPrevWeek();
        String time2 = format(date2, "yyyy-MM-dd");

        return time + "," + time2;
    }

    /**
     * 获取前一周的开始时间
     *
     * @return
     */
    public static Date getBeginDayOfPrevWeek() {
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
        cal.add(Calendar.WEEK_OF_MONTH, -1);
        if (dayofweek == 1) {
            dayofweek -= 7;
        }
        cal.add(Calendar.DATE, 2 - dayofweek);
        return cal.getTime();
    }

    public static Date getEndDayOfPrevWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getBeginDayOfPrevWeek());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        Date weekEndSta = cal.getTime();
        return weekEndSta;
    }


    /**
     * 获取指定时间 当前周的周一至周日的时间
     *
     * @return
     */
    public static List<String> getWeekDataList(String time) {
        List<String> week = new ArrayList<String>();
        try {
            if (StringHelper.isEmpty(time)) {
                time = DateTimeHelper.getNowDay();
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date dataTime = sdf.parse(time);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dataTime);
            // 如果是周日
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                calendar.add(Calendar.DAY_OF_YEAR, -1);
            }
            // 获取当前日期是当周的第i天
            int i = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            // 获取当前日期所在周的第一天
            calendar.add(Calendar.DATE, -i + 1);
            int max = 7;
            for (int j = 0; j < max; j++) {
                if (j > 0) {
                    calendar.add(Calendar.DATE, 1);
                }
                week.add(sdf.format(calendar.getTime()));
                System.err.println(sdf.format(calendar.getTime()));
            }
            return week;
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
        return week;
    }

    /**
     * 仁义日期加减
     *
     * @return
     */
    public static String getDayAddOrReduce(String time, int num) {
        String returnTime = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date dataTime = sdf.parse(time);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dataTime);
            // 如果是周日
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                calendar.add(Calendar.DAY_OF_YEAR, -1);
            }
            calendar.add(Calendar.DATE, num);
            return sdf.format(calendar.getTime());
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
        return returnTime;
    }

    /**
     * 周开始和周结束时间
     *
     * @param time
     * @param isStart
     * @return
     */
    public static String getWeekStartOrEndTime(String time, boolean isStart) {
        String returnTime = null;
        try {
            if (StringHelper.isEmpty(time)) {
                time = DateTimeHelper.getNowDay();
            }

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date dataTime = sdf.parse(time);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dataTime);
            // 如果是周日
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                calendar.add(Calendar.DAY_OF_YEAR, -1);
            }
            // 获取当前日期是当周的第i天
            int i = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            // 获取当前日期所在周的第一天
            calendar.add(Calendar.DATE, -i + 1);
            if (isStart) {
                return sdf.format(calendar.getTime());
            } else {
                calendar.add(Calendar.DATE, 6);
                return sdf.format(calendar.getTime());
            }

        } catch (Exception e) {
            log.error(e.toString(), e);
        }

        return returnTime;
    }

    /**
     * 获取当前日期是多少周 周
     *
     * @return
     */
    public static int getNowWeeks(String time) {
        try {
            Date date = new Date();
            if (StringHelper.isNotEmpty(time)) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                date = sdf.parse(time);
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            // 获取一年中的第几周
            int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
            return weekOfYear;
        } catch (Exception e) {
            log.error(e.toString(), e);
            return 0;
        }
    }


    /**
     * 获取前一天的日期
     *
     * @return
     */
    public static String getFrontDay() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.add(Calendar.DAY_OF_MONTH, -1);
        return sdf.format(now.getTime());

    }

    public static Date getEndDayOfWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getBeginDayOfWeek());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        Date weekEndSta = cal.getTime();
        return weekEndSta;
    }

    /**
     * 获取两个时间之间的所有日期
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public static List<String> getBetweenDate(String startTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList<>();
        try {
            //转化日期类型
            Date startDate = sdf.parse(startTime);
            Date endDate = sdf.parse(endTime);
            //用calendar 进行日期比较判断
            Calendar calendar = Calendar.getInstance();
            while (startDate.getTime() <= endDate.getTime()) {
                //把日期添加到集合中
                list.add(sdf.format(startDate));
                //设置日期
                calendar.setTime(startDate);

                //把日期加一天
                calendar.add(Calendar.DATE, 1);

                //获取增加后的日期
                startDate = calendar.getTime();
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * @return float
     * @Author ccw
     * @Description 秒换算成小时
     * @Date 14:08 2022/6/24
     * @Param [seconds]
     */
    public static String getHours(int seconds) {
        NumberFormat numberFormat = NumberFormat.getInstance();
        //保留几位小数填写几
        numberFormat.setMaximumFractionDigits(3);
        return numberFormat.format((float) seconds / (float) 3600);
    }

    /**
     * @return int
     * @Author ccw
     * @Description 时间差
     * @Date 14:05 2022/6/24
     * @Param [startTime, endTime]
     */
    public static int getTimeDifference2(String startTime, String endTime) throws ParseException {
        SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleFormat.parse(startTime);
        long time = date.getTime();
        Date date2 = simpleFormat.parse(endTime);
        long time2 = date2.getTime();
        long timestamp = time2 - time;
        return (int) (timestamp / 1000);
    }

    /**
     * 小时差
     *
     * @param endTime
     * @param startTime
     * @return
     * @throws ParseException
     */
    public static Double getTimeHours(String endTime, String startTime) throws ParseException {
        try {
            SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date st = simpleFormat.parse(startTime);
            Date et = simpleFormat.parse(endTime);
            long time = et.getTime() - st.getTime();
            DecimalFormat decimalFormat = new DecimalFormat("0.00");
            String format = decimalFormat.format(time * 1.0 / 3600000 * 1.0);
            return Double.valueOf(format);
        } catch (Exception e) {
            return 0.0;
        }
    }

    /**
     * 分钟差
     *
     * @param endTime
     * @param startTime
     * @return
     * @throws ParseException
     */
    public static Long getTimeMine(String endTime, String startTime) throws ParseException {
        try {
            SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date st = simpleFormat.parse(startTime);
            Date et = simpleFormat.parse(endTime);
            long time = et.getTime() - st.getTime();
            double times = Double.parseDouble(time + "");
            double b = times / 1000 / 60;
            return time / 1000 / 60;
        } catch (Exception e) {
            return 0L;
        }
    }

    /**
     * 日期解析为时间戳
     *
     * @param dateString
     * @param format
     * @return Long
     * @description
     * @author cwchen
     * @date 2024/3/16 15:11
     */
    public static Long convertDateStringToTimestamp(String dateString, String format) {
        Date date = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            date = sdf.parse(dateString);
        } catch (ParseException e) {
            log.error("日期解析为时间戳异常", e);
            return null;
        }
        return date.getTime();
    }

    /**
     * 两个日期之间的差值
     *
     * @param startDate
     * @param endDate
     * @return Long
     * @description
     * @author cwchen
     * @date 2024/3/28 20:38
     */
    public static Long getDayDifference(String startDate, String endDate) {
        if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)) {
            return 0L;
        }
        DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date star = dft.parse(startDate);
            Date endDay = dft.parse(endDate);
            Long starTime = star.getTime();
            Long endTime = endDay.getTime();
            Long num = endTime - starTime;
            System.out.println("相差天数为：" + num / 24 / 60 / 60 / 1000);
            return (num / 24 / 60 / 60 / 1000) + 1;
        } catch (ParseException e) {
            log.error("两个日期之间的差值", e);
            return 0L;
        }
    }

    /**
     * 获取当前月的第一天和最后一天
     */
    public static String getMonthFirstAndLastDay() {
        Calendar a = Calendar.getInstance();
        //把日期设置为当月第一天
        a.set(Calendar.DATE, 1);
        //日期回滚一天，也就是最后一天
        a.roll(Calendar.DATE, -1);
        //当月有多少天
        int maxDate = a.get(Calendar.DATE);
        SimpleDateFormat sdfTwo = new SimpleDateFormat("yyyy-MM-");
        String startTime = sdfTwo.format(new Date()) + "01";
        String endTime = sdfTwo.format(new Date()) + maxDate;
        return startTime + " - " + endTime;
    }

    /**
     * 比较两个时间
     * @param startTime
     * @param endTime
     * @return boolean
     * @description
     * @author cwchen
     * @date 2024/4/24 9:55
     */
    public static boolean compareTime(String startTime, String endTime) {
        Long aLong = convertDateStringToTimestamp(startTime, "yyyy-MM-dd");
        Long bLong = convertDateStringToTimestamp(endTime, "yyyy-MM-dd");
        if (aLong > bLong) {
            return false;
        }
        return true;
    }
}
