Solved

Find a future date

Posted on 2006-11-29
7
227 Views
Last Modified: 2010-03-31
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


0
Comment
Question by:blarouche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 18037871
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18037887
DateFormat df = new SimpleDateFormat("yyyymmDD");
int date = Integer.parseInt(df.format(cal.getTime());
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18037891
int date = Integer.parseInt(df.format(cal.getTime()));
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:blarouche
ID: 18037960
Sorry CEHJ


I accepted the answer but I found out an error

My result give me 200611359 which is wrong
0
 

Author Comment

by:blarouche
ID: 18038111
I think there is a mistake in the code.

I changed it for :

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

But it still doesn't work
0
 

Author Comment

by:blarouche
ID: 18038660

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));
            System.out.println(marchdate);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18039611
Yes that's better actually
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
junit as external jar or library 7 58
Running JavaFX on the Raspberry Pi 27 292
Java array 21 150
maximize the sum of fractions 33 76
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question