How to get date which is the sum of any previous date to 7 days next date?

I've a previous date from current date which is saved in database and need to get date 7 days next date. How can i get it?

For example:

i've date 1461560032085 milliseconds. How can i get 7 days next date?

Upvotes: 0

Views: 71

Answers (5)

Supratim Haldar
Supratim Haldar

Reputation: 2426

1 day = 86400000 milliseconds

So 7 days after "1461560032085" will be = 1461560032085 + 86400000 * 7

Hope this helps!

Upvotes: 1

Pooya
Pooya

Reputation: 6136

To calculate 7 days after the current day you should do the following:

nextWeek = yourdate + 7*24*60*60*1000

Upvotes: 0

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

It is very simple to use Calendar class

Calendar calendar = Calendar.getInstance();
calendar.setTime(your_current_date);
calendar.add(Calendar.DAY_OF_YEAR, +7);
Date newDate = calendar.getTime();

Upvotes: 1

Satpal Yadav
Satpal Yadav

Reputation: 81

  private int getaddedDate(int previousdate)
    {
      return previousdate + TimeUnit.DAYS.toMillis(7);
    }

Upvotes: 0

Dilip
Dilip

Reputation: 2734

 public static String getAdded_date(String previous_date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        try {
            c.setTime(sdf.parse(previous_date));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.add(Calendar.DAY_OF_WEEK, 7);  // number of days to add, can also use Calendar.DAY_OF_MONTH in place of Calendar.DATE
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        String output = sdf1.format(c.getTime());

        return output;
    }

Upvotes: 0

Related Questions