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


    /***
         * 获取时间区间 月份开始|结束 时间列表
         * 示例
         *     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;
        }
  • 相关阅读:
    Html-浅谈如何正确给table加边框
    如何在移动设备上调试html5开发的网页
    swiper嵌套小demo(移动端触摸滑动插件)
    移动端如何用swiper实现导航栏效果
    background-color:transparent
    点击按钮 发送短信验证码后60秒倒计时
    placeholder的样式设置
    linux 定时任务crontab
    laravel学习一
    centos 7安装jdk
  • 原文地址:https://www.cnblogs.com/panbingqi/p/13807027.html
Copyright © 2020-2023  润新知