首页 > 编程语言 >java 查询日期列表月末对应上月末,季度末对应上季度末,年末对应上年末,取列表月度,季度,年度区间最后一个

java 查询日期列表月末对应上月末,季度末对应上季度末,年末对应上年末,取列表月度,季度,年度区间最后一个

时间:2024-07-02 11:09:22浏览次数:28  
标签:DateUtil 季度末 FORMAT dateList 列表 add YMD STANDARD 对应

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

相关文章

  • ThinkCMF制作文章列表 <portal:articles 标签报错 Undefined variable $vo
    代码如下:<portal:articleslimit="5"order="post.published_timeDESC"categoryIds="$category_ids"><liclass="tm-recent-post-list-li"><ahref=&......
  • 随机生成50个0-100之间的数字,生成对应个数的随机字母,再按数字大小从小到大排序最后写
    importjava.util.ArrayList;importjava.util.Collections;importjava.util.List;importjava.util.Random;importjava.io.FileNotFoundException;importjava.io.PrintStream;publicclassRandomNum{publicstaticvoidmain(String[]args)throwsFileNotF......
  • 小案例---商城列表案例
    一、项目描述本案例包含标题栏,返回键,刷新键,商品卡片等元素构成。该案例主要为了查看商品图片、商品名称、商品价格。可以支持滑动。该案例效果图如上图所示。二、项目准备2.1初始代码去除无效代码保存以下代码:@Entry@ComponentstructText001{ build(){   ......
  • .Net各大平台与其对应的C#语法版本
    前言: .NET平台与C#语法版本之间有着紧密的对应关系。以下是各个.NET平台版本与它们对应的C#语法版本的详细概述:.NETFramework.NETFramework1.0-C#1.0.NETFramework1.1-C#1.1.NETFramework2.0-C#2.0.NETFramework3.0,3.5-C#3.0.NETFramework4.0......
  • python 列表相关操作
    访问元素index(x):返回列表中第一个值为x的元素的索引。pythonfruits=['apple','banana','cherry']print(fruits.index('banana'))#输出:1count(x):返回列表中值为x的元素的个数。pythonnumbers=[1,2,2,3,2,4]print(numbers.count(2))#输......
  • 鸿蒙开发实践项目——商城列表
     一、项目概述在ArkTS环境中运用各个组件简单构建一个商城列表的页面,要求熟练掌握基本组件的用法以及灵活运用的程度。同时页面布局较为简单,适用于鸿蒙开发的新手的实践项目。总体构建页面最终如下:二、项目结构根据预览图可先构建出一副构架图。同时因为所需编写的代码比......
  • 如何读取 ALV 列表中保存的布局元数据?
    我有一个ALV列表作为程序的输出,并且需要能够动态获取/提取列及其位置。用户还可以将列/位置保存为布局以供将来使用,我希望获取已保存布局的相关信息。我希望以内部表格的形式获取ALV列表的列及其位置,以便进一步使用,例如,生成.xls文件。获取和保......
  • 基本数据类型之列表***
    先来总结下数据类型数字、字符串、布尔型、列表、元组、字典、集合可变数据类型:列表、字典、集合--所谓可变就是可以被修改,且修改后在内存中id不变不可变数据类型:字符串、元组、数字有序:字符串、列表、元组**获取元素的方法包括:索引、切片、for循环无序:字典、集合其中数字......
  • Flutter 长列表优化
    Flutter长列表优化固定列表和长列表的区别固定列表中的组件,每次都会被重新构建ListView.builder会按需构建列表元素,也就是只有那些可见得元素才会调用itemBuilder构建元素减少列表项的构建次数addRepaintBoundaries:将列表项用一个RepaintBoundary(重绘边界)包裹,在......
  • python组合数据类型(列表)
              ......