Click to See Complete Forum and Search --> : How to calculate given date in calendar


awai
October 7th, 1999, 06:49 AM
Hi,

I am just starting to learn Java by myself and now really don't know how to solve my problem.
I have problem in how to calculate calendar. For example, for any given date and given the N date you can calculate the new date.

Please help.

Thanks very much

poochi
October 7th, 1999, 09:58 AM
one solution is :


// Adding 10 days with the current date.

Calendar cal = Calendar.getInstance();
cal.set( Calendar.DATE , cal.get( Calendar.DATE ) +10 );





Another solution with the Date class is :



// Calculate milliseconds for current date and add milliseconds for 10 days with it.
Date d = new Date();
long nSeconds = d.getTime() + ( 10 * 24 * 60 * 60 * 1000 );
d.setTime(nSeconds);





But i am getting weird result when i tried to add 30 days with the current date in Date
class. I dont have time to research on it.

Poochi..