Solved

Find a future date

Posted on 2006-11-29
7
222 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
  • 4
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
Comment Utility
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
Comment Utility
DateFormat df = new SimpleDateFormat("yyyymmDD");
int date = Integer.parseInt(df.format(cal.getTime());
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
int date = Integer.parseInt(df.format(cal.getTime()));
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:blarouche
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
Yes that's better actually
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now