?
Solved

date question

Posted on 2005-03-09
4
Medium Priority
?
198 Views
Last Modified: 2010-03-31
i have two strings.
String date0 = "2005-01-16";
String today = "2005-04-09";

How can i calculate todays date - 2 days ?
and how can i compare the result with date0.

I want to pring  "before  today - 2 days" or "after today - 2 days".

Thx
0
Comment
Question by:ap458889
[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 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 13494756
this example will help you

http://www.javaalmanac.com/egs/java.util/GetAge.html

Regards
Sudhakar
0
 
LVL 37

Accepted Solution

by:
zzynx earned 340 total points
ID: 13494958
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -2);
Date todayMinusTwo = cal.getTime();

SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
Date d0 = null;
try {
   d0 = fmt.parse(date0);
} catch (ParseException ex) {
}

if (d0.before(todayMinusTwo))
   System.out.println("Before today - 2 days");
else if (d0.after(todayMinusTwo))
   System.out.println("After today - 2 days");
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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