zoukankan      html  css  js  c++  java
  • 获取时间区间 月份开始|结束 时间列表

    /***
         * 获取时间区间 月份开始|结束 时间列表
         * 示例
         *     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;
        }
  • 相关阅读:
    2019年----沉淀的一年
    条目八《永不建立auto_ptr的容器》
    条目七《如果容器中包含了通过new操作创建的指针,切记在容器对象析构前将指针delete掉》
    条目六《当心C++编译器中最烦人的分析机制》
    条目五《尽量使用区间成员函数代替它们的单元素兄弟》
    cpu上下文切换
    条目四《用empty来代替检查size()是否为0》
    条目三《确保容器中的副本对象高效而正确》
    ORB与LBP、HOG
    C++
  • 原文地址:https://www.cnblogs.com/panbingqi/p/13807027.html
Copyright © 2011-2022 走看看