Skip to content

Latest commit

 

History

History
35 lines (33 loc) · 1016 Bytes

获取今后多少天后的日期.md

File metadata and controls

35 lines (33 loc) · 1016 Bytes

获取今后多少天后的日期

/**
 * 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);
}