package com.dc.galaxydata.model; import com.dc.common.util.DateUtil; import java.util.ArrayList; import java.util.Date; public class EndDates { public static void main(String[] args) { ArrayList<Date> dateList = new ArrayList<>(); dateList.add(DateUtil.parse("2023-02-15", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-02-17", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-02-24", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-03-03", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-03-10", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-03-17", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-03-24", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-03-31", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-04-04", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-04-07", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-04-14", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-04-21", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-04-28", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-05-05", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-05-12", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-05-19", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-05-26", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-06-02", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-06-09", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-06-16", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-06-21", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-06-30", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-07-07", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-07-14", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-07-21", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-07-28", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-08-04", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-08-11", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-08-18", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-08-25", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-09-01", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-09-08", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-09-15", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-09-22", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-09-28", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-10-13", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-10-20", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-10-27", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-11-03", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-11-10", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-11-17", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-11-24", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-12-01", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-12-08", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-12-15", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-12-22", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-12-29", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2023-12-31", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2024-01-05", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2024-01-12", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2024-01-19", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2024-01-26", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2024-02-02", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2024-02-08", DateUtil.YMD_STANDARD_FORMAT)); dateList.add(DateUtil.parse("2024-02-19", DateUtil.YMD_STANDARD_FORMAT)); Date preDate = null; Date monthDate = null; Date preQuarterDate = null; Date preYearDate = null; Date preMonthDate = null; Date quarterDate = null; Date yearDate = null; for (Date date : dateList) { Date monthEndDate = DateLastEndUtil.getMonthEnd(date); Date preMonthEndDate = DateLastEndUtil.getPreMonthEnd(date); if (preDate != null) { System.out.println("date: " + DateUtil.format(date, DateUtil.YMD_STANDARD_FORMAT) + ",preDate: " + DateUtil.format(preDate, DateUtil.YMD_STANDARD_FORMAT) + ",monthEndDate: " + DateUtil.format(monthEndDate, DateUtil.YMD_STANDARD_FORMAT) + ",preMonthEndDate: " + DateUtil.format(preMonthEndDate, DateUtil.YMD_STANDARD_FORMAT)); if (!DateLastEndUtil.getSameMonthFlag(preDate, date)) { preMonthDate = monthDate; } if (preDate.compareTo(preMonthEndDate) <= 0 && !DateLastEndUtil.getSameMonthFlag(preDate, monthEndDate)) { monthDate = preDate; } } if (preMonthDate != null) { System.out.println("-------preMonthDate: " + DateUtil.format(preMonthDate, DateUtil.YMD_STANDARD_FORMAT) + ",monthDate: " + DateUtil.format(monthDate, DateUtil.YMD_STANDARD_FORMAT)); preMonthDate = null; } Date quarterEndDate = DateLastEndUtil.getQuarterEnd(date); Date preQuarterEndDate = DateLastEndUtil.getPreQuarterEnd(date); if (preDate != null) { System.out.println("date: " + DateUtil.format(date, DateUtil.YMD_STANDARD_FORMAT) + ",preDate: " + DateUtil.format(preDate, DateUtil.YMD_STANDARD_FORMAT) + ",quarterEndDate: " + DateUtil.format(quarterEndDate, DateUtil.YMD_STANDARD_FORMAT) + ",preQuarterEndDate: " + DateUtil.format(preQuarterEndDate, DateUtil.YMD_STANDARD_FORMAT)); if (!DateLastEndUtil.getSameQuarterFlag(preDate, date)) { preQuarterDate = quarterDate; } if (preDate.compareTo(preQuarterEndDate) <= 0 && !DateLastEndUtil.getSameQuarterFlag(preDate, quarterEndDate)) { quarterDate = preDate; } } if (preQuarterDate != null) { System.out.println("-------preQuarterDate: " + DateUtil.format(preQuarterDate, DateUtil.YMD_STANDARD_FORMAT) + ",quarterDate: " + DateUtil.format(quarterDate, DateUtil.YMD_STANDARD_FORMAT)); preQuarterDate = null; } Date yearEndDate = DateLastEndUtil.getYearEnd(date); Date preYearEndDate = DateLastEndUtil.getPreYearEnd(date); if (preDate != null) { System.out.println("date: " + DateUtil.format(date, DateUtil.YMD_STANDARD_FORMAT) + ",preDate: " + DateUtil.format(preDate, DateUtil.YMD_STANDARD_FORMAT) + ",YearEndDate: " + DateUtil.format(yearEndDate, DateUtil.YMD_STANDARD_FORMAT) + ",preYearEndDate: " + DateUtil.format(preYearEndDate, DateUtil.YMD_STANDARD_FORMAT)); if (!DateLastEndUtil.getSameYearFlag(preDate, date)) { preYearDate = yearDate; } if (preDate.compareTo(preYearEndDate) <= 0 && !DateLastEndUtil.getSameYearFlag(preDate, yearEndDate)) { yearDate = preDate; } } if (preYearDate != null) { System.out.println("-------preYearDate: " + DateUtil.format(preYearDate, DateUtil.YMD_STANDARD_FORMAT) + ",YearDate: " + DateUtil.format(yearDate, DateUtil.YMD_STANDARD_FORMAT)); preYearDate = null; } preDate = date; } Date monthEndDate = DateLastEndUtil.getMonthEnd(preDate);//判断stats_date 是否是一个完整自然月季年 if (!DateLastEndUtil.getSameMonthFlag(preDate, monthDate)) { preMonthDate = monthDate; monthDate = preDate; } if (preMonthDate != null) { System.out.println("-------preMonthDate: " + DateUtil.format(preMonthDate, DateUtil.YMD_STANDARD_FORMAT) + ",monthDate: " + DateUtil.format(monthDate, DateUtil.YMD_STANDARD_FORMAT)); } Date quarterEndDate = DateLastEndUtil.getQuarterEnd(preDate);//判断stats_date 是否是一个完整自然月季年 if (!DateLastEndUtil.getSameQuarterFlag(preDate, quarterDate)) { preQuarterDate = quarterDate; quarterDate = preDate; } if (preQuarterDate != null) { System.out.println("-------preQuarterDate: " + DateUtil.format(preQuarterDate, DateUtil.YMD_STANDARD_FORMAT) + ",quarterDate: " + DateUtil.format(quarterDate, DateUtil.YMD_STANDARD_FORMAT)); } Date YearEndDate = DateLastEndUtil.getYearEnd(preDate);//判断stats_date 是否是一个完整自然月季年 if (!DateLastEndUtil.getSameYearFlag(preDate, yearDate)) { preYearDate = yearDate; yearDate = preDate; } if (preYearDate != null) { System.out.println("-------preYearDate: " + DateUtil.format(preYearDate, DateUtil.YMD_STANDARD_FORMAT) + ",YearDate: " + DateUtil.format(yearDate, DateUtil.YMD_STANDARD_FORMAT)); } } }
标签:DateUtil,季度末,FORMAT,dateList,列表,add,YMD,STANDARD,对应 From: https://www.cnblogs.com/yxl-wyb/p/18279509