I used to use the following code to calculate the date of 30 days ago in JDK 1.1.8:
java.sql.Date ToDate = new java.sql.Date(2001, 04, 23-30);
However, the new java.sql.Date(int, int, int) is depreciated in JDK 1.2.2. Just wondering how do we calculate the date of 30 days ago? Any help would be appreciated. Thank you.
Discussions
Web tier: servlets, JSP, Web frameworks: How can I get the date of 30 days ago in JDK1.2.2?
-
How can I get the date of 30 days ago in JDK1.2.2? (2 messages)
- Posted by: Janice Wong
- Posted on: April 23 2001 13:33 EDT
Threaded Messages (2)
- How can I get the date of 30 days ago in JDK1.2.2? by Bougnon Kipre on April 23 2001 17:43 EDT
- How can I get the date of 30 days ago in JDK1.2.2? by Janice Wong on April 23 2001 19:11 EDT
-
How can I get the date of 30 days ago in JDK1.2.2?[ Go to top ]
- Posted by: Bougnon Kipre
- Posted on: April 23 2001 17:43 EDT
- in response to Janice Wong
The constructor you are trying to is deprecate since jkd1.1
The only contructor now takes a long
Try the following code sequence is a suggtested work-around
java.util.Calendar date = java.util.Calendar.getInstance();
// Set your initial date
date.set(2001, 04, 30);
/*
Then go back x days, where n is an int
To add x day ahead, use positive int
To substract x days , use negative int
*/
date.add(Calendar.DATE,-30); // go back 30 days
/*
Similar methos exist for years, months, hours,
minute, seconds respectively
date.set(Calendar.YEAR, years);
date.add(Calendar.MONTH, months);
date.add(Calendar.HOUR, hours);
date.add(Calendar.MINUTE, minutes);
date.add(Calendar.SECOND, seconds);
Where Variable years, months, minutes
and seconds are int.
Use positive values to advance, and negative
values to turn back the calendar
Please check the API for more info
*/
Hope this helps,
Kipre
-
How can I get the date of 30 days ago in JDK1.2.2?[ Go to top ]
- Posted by: Janice Wong
- Posted on: April 23 2001 19:11 EDT
- in response to Bougnon Kipre
Kipre,
Thank you for the advise. I will give it a try. Thank you.
Janice