zoukankan      html  css  js  c++  java
  • JAVA 根据具体年份周数获取日期范围

    /**
    * 根据具体年份周数获取日期范围
    * @param year
    * @param week
    * @param targetNum
    * @return
    */
    public String getWeekDays(int year, int week, int targetNum) {
     

      // 计算目标周数
      if (week + targetNum > 52) {
        year++;
        week += targetNum - 52;
      } else if (week + targetNum <= 0) {
        year--;
        week += targetNum + 52;
      } else {
        week += targetNum;
      }

      SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
      Calendar cal=Calendar.getInstance();

      // 设置每周的开始日期
      cal.setFirstDayOfWeek(Calendar.SUNDAY);

      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.WEEK_OF_YEAR, week);

      cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
      String beginDate = sdf.format(cal.getTime());

      cal.add(Calendar.DAY_OF_WEEK, 6);
      String endDate = sdf.format(cal.getTime());

      return beginDate + "~" + endDate;
    }

  • 相关阅读:
    concrete maths ch4 number theory
    Aho-Corasick algorithm
    Finding repetitions
    Suffix Automaton
    Z-function and its calculation
    mongodb安装与启动
    centos redis 集群搭建
    nginx实现热部署(平滑升级)
    nacos集群部署安装
    springboot+zookeeper+dubbo整合
  • 原文地址:https://www.cnblogs.com/mithrandirw/p/8746468.html
Copyright © 2011-2022 走看看