• 获取时间区间 月份开始|结束 时间列表


    /***
         * 获取时间区间 月份开始|结束 时间列表
         * 示例
         *     param
         *         startLocalDateTime 2020-03-02 12:22:22
         *         endLocalDateTime  2020-05-22 18:18:18
         *     return
         *         2020-03-02 12:22:22,2020-03-31 23:59:59.999
         *         2020-04-01 00:00:00,2020-04-30 23:59:59.999
         *         2020-05-01 00:00:00,2020-05-22 18:18:18
         * @param startLocalDateTime
         * @param endLocalDateTime
         * @return
         */
        public static List<LocalDateTime[]> getLocalDateTimeIntervalMonthStartEndTime(LocalDateTime startLocalDateTime,LocalDateTime endLocalDateTime){
            if (startLocalDateTime.isAfter(endLocalDateTime)){
                LocalDateTime temp=startLocalDateTime;
                startLocalDateTime=endLocalDateTime;
                endLocalDateTime=temp;
            }
            List<LocalDateTime[]> localDateTimeList=new ArrayList<>();
    
            LocalDateTime currDateTime=startLocalDateTime;
            LocalDateTime currMonthEndDateTime = LocalDateTime.of(LocalDate.of(currDateTime.getYear(),currDateTime.getMonth(),currDateTime.getDayOfMonth()), LocalTime.MAX).with(TemporalAdjusters.lastDayOfMonth());
    
            if (currMonthEndDateTime.isBefore(endLocalDateTime)) {
                localDateTimeList.add(new LocalDateTime[]{currDateTime, currMonthEndDateTime});
            } else {
                localDateTimeList.add(new LocalDateTime[]{startLocalDateTime, endLocalDateTime});
            }
    
            do{
                currDateTime = LocalDateTime.of(LocalDate.of(currDateTime.getYear(),currDateTime.getMonth(),currDateTime.getDayOfMonth()), LocalTime.MIN).with(TemporalAdjusters.firstDayOfNextMonth());
                currMonthEndDateTime = LocalDateTime.of(LocalDate.of(currDateTime.getYear(),currDateTime.getMonth(),currDateTime.getDayOfMonth()), LocalTime.MAX).with(TemporalAdjusters.lastDayOfMonth());
                if (currMonthEndDateTime.isBefore(endLocalDateTime)) {
                    localDateTimeList.add(new LocalDateTime[]{currDateTime, currMonthEndDateTime});
                } else {
                    if (currDateTime.isBefore(endLocalDateTime)) {
                        localDateTimeList.add(new LocalDateTime[]{currDateTime, endLocalDateTime});
                    }
                }
            }while(currMonthEndDateTime.isBefore(endLocalDateTime));
    
            return localDateTimeList;
        }
  • 相关阅读:
    iOS Xcode8的适配
    iOS从生成证书到打包上架-02(详细2016-10最新)
    iOS从生成证书到打包上架-01(详细2016-10最新)
    PHP读取CSV文件
    magento批量导入评论加星
    magento调用static block
    Magento Block的几种调用方式
    JFinal项目中获取根目录
    清除UTF-8编码文件前端的DOM
    PhpStorm注册码(2,3,4,5)通用
  • 原文地址:https://www.cnblogs.com/panbingqi/p/13807027.html
Copyright © 2020-2023  润新知