• java获取日历格式的日期数据


      

    需求是这样的,需要以整体的样子展示日历,比如,5 *7 或者 6* 7 的格式 

    我需要把日期数据获取出来,所以我通过后台的得到需要的数据,分析需要3部分数据

    • 中间的一部分直接获取一个月的第一天和最后一天,
    • 前一部分和后一部分通过TemporalAdjusters对应的方法获取,
    • TemporalAdjusters.dayOfWeekInMonth 可以获取当前月的第X星期的星期几对应的日期,我们可以利用这个处理。
    /**
         * <per>
         * <p>返回六行日历系统整月之外的日期区间  </p>
         * <per/>
         * @param date
         * @return java.time.LocalDate[]
         * @throws
         * @Description : TODO Return date range beyond the full month calendar system
         *                   TODO Demo :2020-10-01 -->  [2020-09-27, 2020-09-30, 2020-11-01, 2020-11-07]
         * @author Liruilong
         * @Date 2020/11/5 10:50
         **/
        public static LocalDate[] calendarOsToDay(LocalDate date) {
            LocalDate firstDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth());
            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            LocalDate monthSaturday = date.with(TemporalAdjusters.dayOfWeekInMonth(6, DayOfWeek.SATURDAY));
            LocalDate monthSunday = date.with(TemporalAdjusters.dayOfWeekInMonth(0, DayOfWeek.SUNDAY));
            LocalDate[] localDate = new LocalDate[]{firstDayOfMonth,firstDayOfMonth,lastDayOfMonth,lastDayOfMonth};
           // 整月之前
            if (firstDayOfMonth.getDayOfWeek().getValue() != DayOfWeek.SUNDAY.getValue()){
                LocalDate lastMonth = LocalDate.of(date.getYear(),  date.getMonthValue() == 1 ? 12 :  date.getMonthValue() - 1  , 1);
                localDate[0] = monthSunday;
                localDate[1] = lastMonth.with(TemporalAdjusters.lastDayOfMonth());
            }
            // 整月之后
             int  day = (int)(localDate[3].toEpochDay() - localDate[0].toEpochDay());
            if (lastDayOfMonth.getDayOfWeek().getValue() != DayOfWeek.SATURDAY.getValue()){
                localDate[2] = date.with(TemporalAdjusters.firstDayOfNextMonth());
                localDate[3] = monthSaturday;
            }else if (day == 34){
                localDate[2] = date.with(TemporalAdjusters.firstDayOfNextMonth());
                localDate[3] =localDate[2].with(TemporalAdjusters.dayOfWeekInMonth(1, DayOfWeek.SATURDAY));
            }else if ( day == 27){
                localDate[2] = date.with(TemporalAdjusters.firstDayOfNextMonth());
                localDate[3] =localDate[2].with(TemporalAdjusters.dayOfWeekInMonth(2, DayOfWeek.SATURDAY));
            }
            return localDate;
        }
  • 相关阅读:
    SQL Server 隐式转换引发的死锁
    C# List按某对象的属性分组 IGrouping
    C# 正则表达式获取json字符串中的键值
    .NET程序修改 ConfigurationManager 后,不需要重启IIS也可刷新Web.config配置文件
    相同结构的多个表合并到一个表的实现方法
    WCF系列_WCF影响客户端导出Excel文件的实现
    WCF系列_WCF如何选择不同的绑定
    WCF系列_WCF常用绑定选择
    JS生成URL二维码
    win 常用CMD命令备忘
  • 原文地址:https://www.cnblogs.com/liruilong/p/13948009.html
Copyright © 2020-2023  润新知