| Author |
HELP needed on DATE
|
Aero Berien
Greenhorn
Joined: Mar 15, 2004
Posts: 1
|
|
Hi there everyone, pls help me . i have a question as above "Code a Java class called Calendar which has a static variable of type Date(initialised to 1st January 2004), a static void method called tock(int days) to advance the variable by the specified number of days, and a static Date method called getDate() to return the current date.". What i was thinking to write is. public class Calendar { Date myDate = new Date(); myDate = java.sql.Date.valueOf("2004-01-01"); //but my fren said i could use the toString() instead public static void tock(int days) { int i = 1; while i < days; Date = Date + 1; // i am not sure what i am doing ...i am just a beginner .pls help } public static Date getDate() { return Date; } Are my answers correct ..? how do i advance the variable (date) by the number of specified days ? the asnwer need to print out, say 4 days , u need to print 01 Jan , 02Jan , 03 Jan , 04 Jan... anyone please help ..
|
 |
Jeroen Wenting
Ranch Hand
Joined: Oct 12, 2000
Posts: 5093
|
|
your code Try this instead: To print out as a String, look at SimpleDateFormat from the API docs.
|
42
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
Or you can set the date like this: I normally use 'cal.add(GregorianCalendar.DATE, days);' when I want to add days to a date - and this works with leapyear as well. Ren� [ March 16, 2004: Message edited by: Rene Larsen ]
|
Regards, Rene Larsen
Dropbox Invite
|
 |
 |
|
|
subject: HELP needed on DATE
|
|
|