• 根据传入时间得到上一年下一年第一天和最后一天


    /**
      * 获取上一年第一天的时间 返回yyyy-MM-dd
      *
      * @param enDate
      * @return
      */
     public Date getPreviousYearFirst(Date enDate) {
      Date date = enDate;
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");// 可以方便地修改日期格式
      String years = dateFormat.format(date);//得到年
      int years_value = Integer.parseInt(years);
      years_value--;//上一年
      String fristStr = years_value + "-01-01";//得到上一年第一天
      try {
       date = new SimpleDateFormat("yyyy-MM-dd").parse(fristStr);
      } catch (ParseException e) {
       e.printStackTrace();
      }
      return date;
     }

     /**
      * 获取上一年最后一天的时间 返回yyyy-MM-dd
      * @param enDate
      * @return
      */
     public Date getPreviousYearEnd(Date enDate) {
      Date date = enDate;
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");// 可以方便地修改日期格式
      String years = dateFormat.format(date);//得到年
      int years_value = Integer.parseInt(years);
      years_value--;//上一年
      String fristStr = years_value + "-12-31";//得到上一年最后一天
      try {
       date = new SimpleDateFormat("yyyy-MM-dd").parse(fristStr);
      } catch (ParseException e) {
       e.printStackTrace();
      }
      return date;
     }

     /**
      * 获取下一年第一天的时间 返回yyyy-MM-dd
      *
      * @param enDate
      * @return
      */
     public Date getNextYearFirst(Date enDate) {
      Calendar curr = Calendar.getInstance();
      curr.setTime(enDate);//使用给定的 enDate 设置此 Calendar 的时间
      curr.set(Calendar.YEAR,curr.get(Calendar.YEAR)+1);//得到下一年
      Date date=curr.getTime();
      GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
      gc.setTime(date);
      gc.get(Calendar.YEAR);
      gc.set(gc.get(Calendar.YEAR), 0, 1);//设置下一年第一天
      return gc.getTime();
     }

     /**
      * 获取下一年最后一天的时间 返回yyyy-MM-dd
      *
      * @param enDate
      * @return
      */
     public Date getNextYearEnd(Date enDate) {
      Calendar curr = Calendar.getInstance();
      curr.setTime(enDate);
      curr.set(Calendar.YEAR,curr.get(Calendar.YEAR)+1);//得到下一年
      Date date=curr.getTime();
      GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
      gc.setTime(date);
      gc.get(Calendar.YEAR);
      gc.set(gc.get(Calendar.YEAR), 11, 31);//设置下一年最后一天
      return gc.getTime();
     }

  • 相关阅读:
    [原创]K8 Struts2 Exp 20170310 S2-045(Struts2综合漏洞利用工具)
    [原创]Struts2奇葩环境任意文件上传工具
    Nmap扫描基础常用命令(包含进阶使用)
    Burp Suite Intruder中爆破模式介绍
    Debian Security Advisory(Debian安全报告) DSA-4412-1 drupal7 security update
    Debian Security Advisory(Debian安全报告) DSA-4411-1 firefox-esr security update
    Debian Security Advisory(Debian安全报告) DSA-4410-1 openjdk-8 security update
    kindeditor<=4.1.5 文件上传漏洞利用
    Access数据库SQL注入(Access SQL Injection)
    渗透测试常见开放端口及利用
  • 原文地址:https://www.cnblogs.com/mingtian521/p/3739181.html
Copyright © 2020-2023  润新知