hi all, i am having a slight problem manipulating dates The code requires a inpout odf date in string format (yyyymmdd) eg 20021218 what i need is a function which will calculate one day less from the given day i.e 20021217 if it is 20030101 .. it should give me 20021231 also take care of feb and leap year.. i need this asap .. deadlines to meet consider this as an SOS Thanx in advance Chhaya
Check out java.text.SimpleDateFormat for a way to output dates in a particular format.... simply. Using java.util.Calendar you can add -1 to the day field to get the previous day. Dave
girish rateshwar
Ranch Hand
Joined: Mar 04, 2001
Posts: 97
posted
0
Hi, Well as david suggested, using the calendar class in the util package. ----- calendar c1= new calendar(); Date d1= new Date(); And passing a parameter to the setTime() method--object of the date class. while using the get() function: c1.get((Calendar.Date)-1)<<---- Regards, [ December 19, 2002: Message edited by: girish rateshwar ]
Girish
Senthil B Kumar
Ranch Hand
Joined: Feb 09, 2004
Posts: 140
posted
0
import java.util.Date; import java.util.Calendar; public class Prev { public static void main(String args[]) { Calendar xx = Calendar.getInstance(); Date dt = null; xx.add(Calendar.DATE,-1); dt = xx.getTime(); System.out.println("Yesterday Is : " + dt.getDate()); } }
Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside HereWEBlog
Blake Minghelli
Ranch Hand
Joined: Sep 13, 2002
Posts: 331
posted
0
Originally posted by girish rateshwar: Hi, Well as david suggested, using the calendar class in the util package. ----- calendar c1= new calendar(); Date d1= new Date();
And passing a parameter to the setTime() method--object of the date class.
while using the get() function: c1.get((Calendar.Date)-1)<<----
Regards,
[ December 19, 2002: Message edited by: girish rateshwar ]
I think you have the get() and add() methods mixed up. The get() method simply returns one of the fields of a Calendar object, it does not alter the date like the add() method does.
Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.