This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes parsing string in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "parsing string in java" Watch "parsing string in java" New topic
Author

parsing string in java

swapnil paranjape
Ranch Hand

Joined: May 15, 2005
Posts: 126
hi i am currently facing one problem

i have one string like this "23-aug-2004"

other string is like "25-aug-2005"


i need to parse these srtings and get the difference between them in no of days.

i have used parse function

DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
Date d22 = df.parse(d1);
Date d23 = df.parse(d2);

but using this i can only compre strings but cant find the difference..

for this i think i need to parse it and convert into interger and then find difference..
can you pls suggest how should i do it?
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
One way to do this would be to use substring() method and get the 'year', 'month' and 'day' parts of both the dates and then manually calculate the difference.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Continue on with
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
http://joda-time.sourceforge.net/


There is no emoticon for what I am feeling!
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923


What do you think is the reason for using two Ms in the format?


http://home.arcor.de/hirnstrom/bewerbung
 
jQuery in Action, 2nd edition
 
subject: parsing string in java