How do I add 2 weeks to a Date in java?

I will show you how we can do it in Java 8. Here you go:

public class DemoDate {
    public static void main(String[] args) {
        LocalDate today = LocalDate.now();
        System.out.println("Current date: " + today);

        //add 2 week to the current date
        LocalDate next2Week = today.plus(2, ChronoUnit.WEEKS);
        System.out.println("Next week: " + next2Week);
    }
}

The output:

Current date: 2016-08-15
Next week: 2016-08-29

Java 8 rocks !!


Use Calendar and set the current time then user the add method of the calendar

try this:

int noOfDays = 14; //i.e two weeks
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateOfOrder);            
calendar.add(Calendar.DAY_OF_YEAR, noOfDays);
Date date = calendar.getTime();

Try this to add two weeks.

long date = System.currentTimeMillis() + 14 * 24 * 3600 * 1000;
Date newDate = new Date(date);

Use Calendar

    Date date = ...
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.WEEK_OF_MONTH, 2);
    date = c.getTime();

Tags:

Datetime

Java