Add 8 days to the current date and print out the date and time in Java
Description
The following code shows how to add 8 days to the current date and print out the date and time.
Example
//from ww w .j a va2 s . c om
import java.text.DateFormat;
import java.util.Calendar;
public class Main {
public static void main(String s[]) {
Calendar cal = Calendar.getInstance();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.MEDIUM);
System.out.println(df.format(cal.getTime()));
cal.add(Calendar.DATE, 8);
System.out.println(df.format(cal.getTime()));
}
}
The code above generates the following result.