Question: Anyone know a simple way using Java calendar to subtract X days from a date?

I have not been able to find any function which allows me to directly subtract X days from a date in Java. Can someone point me to the right direction?

Answer: 
[Anson's answer](https://stackoverflow.com/questions/212321/anyone-know-a-simple-way-using-java-calendar-to-subtract-x-days-to-a-date#212334) will work fine for the simple case, but if you're going to do any more complex date calculations I'd recommend checking out [Joda Time](http://joda-time.sourceforge.net/). It will make your life much easier.

FYI in Joda Time you could do

```
DateTime dt = new DateTime();
DateTime fiveDaysEarlier = dt.minusDays(5);

```
It can be done easily by the following

```
Calendar calendar = Calendar.getInstance();
        // from current time
        long curTimeInMills = new Date().getTime();
        long timeInMills = curTimeInMills - 5 * (24*60*60*1000);    // `enter code here`subtract like 5 days
        calendar.setTimeInMillis(timeInMills);
        System.out.println(calendar.getTime());

        // from specific time like (08 05 2015)
        calendar.set(Calendar.DAY_OF_MONTH, 8);
        calendar.set(Calendar.MONTH, (5-1));
        calendar.set(Calendar.YEAR, 2015);
        timeInMills = calendar.getTimeInMillis() - 5 * (24*60*60*1000);
        calendar.setTimeInMillis(timeInMills);
        System.out.println(calendar.getTime());

```