Solved

Find a future date

Posted on 2006-11-29
7
228 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

627 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