How to add 3 days to a date to get a newdate

Hi all,I have a date in this formatJUL 28, 2001I want to add 3 days and get the new date.Does anyone know how to do this.Thanks in advanceAdam
[198 byte] By [adamrau] at [2007-9-26 1:40:28]
# 1

1. Create a date based on your text.

2. Roll the date forward.

3. Print out the result.String start = "JUL 28, 2001";

SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");

Date d = sdf.parse(start);

GregorianCalender gc = new GregorianCalendar();

gc.setTime(d);

gc.roll(Calendar.DAY_OF_YEAR, 3);

Date end = gc.getTime();

System.out.println(end);

I don't remember the behavior of the GregorianCalendar if a year boundary is crossed on the roll, so watch for it.

cafal at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi,I am getting an error stating that GregorianCalendar is not found. Am I missing an import or something.THANKSAdam
adamrau at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Check if u have ur code importing java.util and java.textur first line of code should be something like: <%@ page language="java" errorPage="" isErrorPage="false" import="java.util.*,java.text.*" %>
vishvesh_obla at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Tried adding the imports and still get this error: Class _pages.GregorianCalender not found. GregorianCalender gc = new GregorianCalendar();
adamrau at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Look carefully that you have the typo there...In java.util.*, You can find GregorianCalendar.java but there is no GregorianCalender.java.Albert K.T.Tan
kttan at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
> I don't remember the behavior of the GregorianCalendar> if a year boundary is crossed on the roll, so watch for it. roll does not change the year. Use add instead.
nerd2004 at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
I think you'll find that instead ofGregorianCalendar gc = new GregorianCalendar()if you putCalendar gc = new GregorianCalendar()this will work. I just did something similar last week.
lizmarc at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
How to add 3 days to a date to get a newdate
alphao474 at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

import java.util.Calendar;

import java.util.GregorianCalendar;

import java.util.Date;

GregorianCalendar cal = new GregorianCalendar(2001,6,28);

cal.add(Calendar.DAY_OF_YEAR, 3);

Date newDate = cal.getTime();

System.out.println(newDate);

nep100 at 2007-6-29 2:30:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...