This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes initialise & add date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "initialise & add date" Watch "initialise & add date" New topic

initialise & add date

james ong

Joined: Aug 01, 2006
Posts: 2
hihi.. how can i do a initialzation of date to 2nd June 2005, then add 3 days of the last date value? below is a sample of my code.

import java.util.Date;

public class Calendar {
private static Date today;

public static Date getDate() {
return (Date)today.clone();

public static void tock(int days) {
//add advance date (7 days)???
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

I won't post code here, you can figure it out by looking at the SimpleDateFormat class.
Another thing, avoid to call your class "Calendar", because it's already an Java API class.

[My Blog]
All roads lead to JavaRanch
James Brown

Joined: Aug 01, 2006
Posts: 4
yes, I think you can use these apis and codes:


public Date getTheAfterDay(Date date, int days) {
GregorianCalendar startCalendar = new GregorianCalendar();
startCalendar.add(GregorianCalendar.DATE, days);
return startCalendar.getTime();

You need import java.util.Date and java.util.GregorianCalendar .
Good Luck!
if you have any qustions please contact me , my msn

good luck everyone
I agree. Here's the link:
subject: initialise & add date
Similar Threads
Date and Calendar
add day to current date
Date and Calender help
Wants to add days in Date.. please help
how to add 30 days to current data?