Hi All, I want to display a Date that is 30 days ago from today, and I used Date object here is my code,
However, the display result is incorrect. i.e. The month value is incorrect, today is Jun 4, so 30 days ago, the month should be May (which is 4 numerically). can somebody tell me what i did wrong, or rather, let me know if I should use something different to get the date that is 30 days ago
Originally posted by Paul Sturrock: I think you should have a look at the Calendar object and its roll(int field, int value) method, which you should find a little easier to use.
But the roll methods only takes care of the field you use, not the larger fields though. For example, if today is June 4, and I want it to be 30 days ago, then only the Day dispaly will be correct not the month, any other suggestions?
You can also use Calendar's add() method rather than roll(), to make things simpler. And note that Date's getXXX() methods are deprecated. Better to use a SimpleDateFormat, or a Calendar, to extract this info from a Date. (Or use the Date's toString() method, which may be exactly what you want.)