Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parsing string in java

 
swapnil paranjape
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20969
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Continue on with
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://joda-time.sourceforge.net/
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What do you think is the reason for using two Ms in the format?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic