zoukankan      html  css  js  c++  java
  • (转)获得指定日期的前一天 后一天

    /**
    * 获得指定日期的前一天
    * @param specifiedDay
    * @return
    * @throws Exception
    */
    public static String getSpecifiedDayBefore(String specifiedDay){
    //SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    Date date=null;
    try {
    date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
    } catch (ParseException e) {
    e.printStackTrace();
    }
    c.setTime(date);
    int day=c.get(Calendar.DATE);
    c.set(Calendar.DATE,day-1);

    String dayBefore=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
    return dayBefore;
    }
    /**
    * 获得指定日期的后一天
    * @param specifiedDay
    * @return
    */
    public static String getSpecifiedDayAfter(String specifiedDay){
    Calendar c = Calendar.getInstance();
    Date date=null;
    try {
    date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
    } catch (ParseException e) {
    e.printStackTrace();
    }
    c.setTime(date);
    int day=c.get(Calendar.DATE);
    c.set(Calendar.DATE,day+1);

    String dayAfter=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
    return dayAfter;
    }

  • 相关阅读:
    配置禅道遇到的那些事儿
    HDU 1181
    HDU1016
    HDU 1518
    2015长春区域赛赛后总结
    Codeforces Round #322 (Div. 2) A B C
    Codeforces Round #325 (Div. 2) A B
    Codeforces Round #324 (Div. 2) A B
    CSU 1530
    CSU 1535
  • 原文地址:https://www.cnblogs.com/wangyt223/p/4202899.html
Copyright © 2011-2022 走看看