Java Day Add getFutrueDate(Date oldDate, int addDay)

Here you can find the source of getFutrueDate(Date oldDate, int addDay)

Description

get Futrue Date

License

Open Source License

Declaration

public static Date getFutrueDate(Date oldDate, int addDay) 

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;
import java.util.TimeZone;

public class Main {
    /**//from w  ww  .  j a  va 2 s  .c  o  m
     * yyyy-MM-dd
     */
    static public final String FORMAT_DATE_ONLY = "yyyy-MM-dd";

    public static Date getFutrueDate(Date oldDate, int addDay) {
        Calendar c = Calendar.getInstance();
        c.setTime(oldDate);
        c.add(Calendar.DATE, addDay);

        return c.getTime();
    }

    public static Date getFutrueDate(String oldDate, int addDay) {
        Calendar c = Calendar.getInstance();
        c.setTime(parse(oldDate, FORMAT_DATE_ONLY));
        c.add(Calendar.DATE, addDay);

        return c.getTime();
    }

    public static Date parse(String str, String format) {
        try {
            SimpleDateFormat sf = new SimpleDateFormat(format);
            sf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            return sf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. addDayToString(String strDate, int days)
  2. addOneDay(String strDate)
  3. addOneDayForamt(String date, String format, Integer addDate)
  4. AddUtilDate(String strDate, int iDays)
  5. getAddDay(int day)