Find a future date

Hi Experts

I would like to find what will be the date for the current  year on March first - 5 days.

I would like to get this date as an int this format :  example 20070220.

How would I do that ?

Thank you

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Calendar cal =  Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.FEBRUARY);
cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH));
cal.add(Calendar.Date, -4);
// Now format the Date

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DateFormat df = new SimpleDateFormat("yyyymmDD");
int date = Integer.parseInt(df.format(cal.getTime());
int date = Integer.parseInt(df.format(cal.getTime()));
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

blaroucheAuthor Commented:
Sorry CEHJ

I accepted the answer but I found out an error

My result give me 200611359 which is wrong
blaroucheAuthor Commented:
I think there is a mistake in the code.

I changed it for :

Calendar cal = Calendar.getInstance();
            cal.set(Calendar.MONTH, Calendar.FEBRUARY);
            cal.add(Calendar.DATE, -4);
            DateFormat df = new SimpleDateFormat("yyyymmDD");
            int date = Integer.parseInt(df.format(cal.getTime()));

But it still doesn't work
blaroucheAuthor Commented:

I found something that works for me.

Calendar cal = Calendar.getInstance();
            cal.set(Calendar.MONTH, Calendar.MARCH);
            cal.set(Calendar.DATE, 01);
            cal.add(Calendar.DATE, -5);
            Date myDate = cal.getTime();
            DateFormat df = new SimpleDateFormat("yyyyMMdd");
            int marchdate = Integer.parseInt(df.format(myDate));
Yes that's better actually
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.