get Date After Someday - Android java.util

Android examples for java.util:Day

Description

get Date After Someday

Demo Code


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

public class Main{

    public static String getDateAfterSomeday(String firstStart, int i) {

        Calendar c = Calendar.getInstance();

        try {//  w  w w .  j a v  a2s .  c  om
            c.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(firstStart));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        long sTime = c.getTimeInMillis();

        long addTime = i * 24 * 60 * 60 * 1000;

        long eTime = sTime + addTime;
        Date date = new Date(eTime);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        return sdf.format(date);
    }

}

Related Tutorials