Java Day of getStringAfterNDay(String str, int n)

Here you can find the source of getStringAfterNDay(String str, int n)

Description

get String After N Day

License

Open Source License

Declaration

public static String getStringAfterNDay(String str, int n) 

Method Source Code

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

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

public class Main {
    public static String getStringAfterNDay(String str, int n) {
        Calendar ca = parseStringToCalendar(str);
        if (ca == null) {
            return null;
        }/* w w  w .  j av a 2 s. c  o  m*/
        ca.add(Calendar.DATE, n);
        String strDate = ca.get(Calendar.YEAR) + "-";
        int intMonth = ca.get(Calendar.MONTH) + 1;
        if (intMonth < 10) {
            strDate += "0" + intMonth + "-";
        } else {
            strDate += intMonth + "-";
        }
        int intDay = ca.get(Calendar.DATE);
        if (intDay < 10) {
            strDate += "0" + intDay;
        } else {
            strDate += intDay;
        }
        return strDate;
    }

    public static Calendar parseStringToCalendar(String strDate) {
        java.util.Date date = parseStringToUtilDate(strDate);
        if (date == null) {
            return null;
        }
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        return ca;
    }

    public static java.util.Date parseStringToUtilDate(String strDate) {

        java.util.Date date = null;
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            date = df.parse(strDate);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return date;
    }
}

Related

  1. getSpecifiedDayAfter(String specifiedDay, int afterDay)
  2. getSpecifiedDayTimeAfter(Date date)
  3. getStandardDayFormat(Date day)
  4. getStartDate(int days, String strEndDate)
  5. getStartDateByDays(Date endDate, int days)
  6. getStringDay(Calendar cal)
  7. getTargetDay(String day, int beforeOrAfterDays)
  8. getTheDayBefore(Date date)
  9. getThursday(String date)