Java Day of getNDayAfterCurrentDate(String dateStr, String dateFormat, int n)

Here you can find the source of getNDayAfterCurrentDate(String dateStr, String dateFormat, int n)

Description

get N Day After Current Date

License

Open Source License

Declaration

public static String getNDayAfterCurrentDate(String dateStr, String dateFormat, int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static String getNDayAfterCurrentDate(String dateStr, String dateFormat, int n) {
        try {//from   w w  w .  j a va  2  s.c o m
            Calendar c = Calendar.getInstance();
            Date date = parse(dateStr, dateFormat);
            c.setTime(date);
            c.add(c.DAY_OF_MONTH, n);
            return c.get(c.YEAR) + "-" + (c.get(c.MONTH) + 1) + "-" + c.get(c.DATE);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
    }

    public static Date parse(String strDate, String pattern) throws ParseException {
        try {
            return getFormatter(pattern).parse(strDate);
        } catch (ParseException pe) {
            throw new ParseException("Method parse in Class DateUtil  err: parse strDate fail.",
                    pe.getErrorOffset());
        }
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. getIntervalDate(String date, int intervalDays)
  2. getIntervalDays(Date fDate, Date oDate)
  3. getIntevalDays(String startDate, String endDate)
  4. getLateInTheDay(Date date)
  5. getLatest7Day()
  6. getOtherDayLastUpdateTimeFormat()
  7. getPaxBirthday()
  8. getPriorDay(int offset, String pattern)
  9. getRunningTime(Date date, SimpleDateFormat sday, String line)