09-28-2008 05:34 PM - edited 09-28-2008 05:48 PM
Hi! I'm a C# programmer who's new to Java and I'm trying to subtract x numbers of days to a specific date. How can I do this in Java? Thank you!
09-28-2008 06:50 PM - edited 09-28-2008 07:34 PM
Another problem arises.
Calendar c = Calendar.getInstance();
cannot find symbol
symbol : method(int,int)
09-28-2008 09:31 PM
Can't find the Calendar.add method in the API doc, so doesn't look like that is supported.
One way to achieve what you want that immediately comes to mind is as follows, however you may need to be aware that this is subtracting 50*24 hours from the time, and if the 50 days included Daylight saving change, then the 50 days might more accurately contain 50*24+1 or 50*24-1 hours.
Calendar c = Calendar.getInstance(); c.set(Calendar.MONTH, mo); c.set(Calendar.DAY_OF_MONTH, day); c.set(Calendar.YEAR, year); long ctime = c.getTime().getTime(); long ctimeMinus50Days = ctime - 50L * ((long)DatetimeUtilities.ONEDAY); // not usre the 'longs are needed c.setTime(new Date(ctimeMinus50Days);