获取今后多少天后的日期

来源:互联网 发布:阿里云搭建网站全过程 编辑:程序博客网 时间:2024/06/11 00:50

获取今后多少天后的日期

/** * Get the date some days later. * @param year the year * @param month month of the year * @param day day of the month * @return if the parameter is illegal this will return null */@SuppressLint("SimpleDateFormat")private static String getClosingDate(int year, int month, int day) {    final int internalDay = 31;    final String pattern = "yyyy-MM-dd";    DateFormat dateFormat = new SimpleDateFormat(pattern);    Date closingDate;    try {        Calendar thisDay = Calendar.getInstance();        thisDay.set(Calendar.YEAR, year);        thisDay.set(Calendar.MONTH, month - 1);// the first month of the year is 0.        thisDay.set(Calendar.DAY_OF_MONTH, day);        thisDay.add(Calendar.DAY_OF_MONTH, internalDay);        closingDate = thisDay.getTime();    } catch (Exception e) {        e.printStackTrace();        return null;    }    return dateFormat.format(closingDate);}

  • 邮箱 :charon.chui@gmail.com
  • Good Luck!
0 0