zoukankan      html  css  js  c++  java
  • JAVA使用LocalDate获取当前日期所在季度的开始日期和结束日期


    需要使用jdk1.8及以上

        /**
         * 获取当前日期所在季度的开始日期和结束日期
         * 季度一年四季, 第一季度:1月-3月, 第二季度:4月-6月, 第三季度:7月-9月, 第四季度:10月-12月
         * @param isFirst  true表示查询本季度开始日期  false表示查询本季度结束日期
         * @return
         */
        public static LocalDate getStartOrEndDayOfQuarter(Boolean isFirst){
            LocalDate today=LocalDate.now();
            LocalDate resDate = LocalDate.now();
            if (today == null) {
                today = resDate;
            }
            Month month = today.getMonth();
            Month firstMonthOfQuarter = month.firstMonthOfQuarter();
            Month endMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2);
            if (isFirst) {
                resDate = LocalDate.of(today.getYear(), firstMonthOfQuarter, 1);
            } else {
                resDate = LocalDate.of(today.getYear(), endMonthOfQuarter, endMonthOfQuarter.length(today.isLeapYear()));
            }
            return resDate;
        }


    LocalDate转换成Date参考:https://www.cnblogs.com/pxblog/p/13935825.html

    JAVA获取指定日期的一天的开始时刻(时间)和结束时刻(时间):https://www.cnblogs.com/pxblog/p/13203471.html

    -----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------ (蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)
  • 相关阅读:
    并查集
    强联通分量,缩点
    最短路径
    最小生成树
    拓扑排序
    图的遍历
    图论基础知识
    数据库四种隔离级别
    MySQL 索引 乐观锁 悲观锁
    MYSQL+正则
  • 原文地址:https://www.cnblogs.com/pxblog/p/13935746.html
Copyright © 2011-2022 走看看