Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calculate duration between two dates

 
tejeshwar sahu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please give me solution how to calculate duration between two dates. its very arrgent.
thanking you!
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, tradition way is to chnage them into milliseconds, using getTime() method of Date class, then after you got the difference back, change it back to Date...

But there is another tool available out there which you don't need such thing to do... You might want to have a look at their site...
http://joda-time.sourceforge.net

Even though there is a need to compensate for the learning curve, you won't regreat using that... I always use that, whenever I have to deal with Date-related stuff in my work, since I know how to use them... I got to know about that here in the Ranch as well...
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, tradition way is to chnage them into milliseconds, using getTime() method of Date class, then after you got the difference back, change it back to Date...


Change it back to date ? But why ? The difference should be in terms of x days and not date right?
For e.g. What is the duration between today and saturday ? It will be 2 days and some hours , right.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this thread at the Sun forum
http://forum.java.sun.com/thread.jspa?threadID=581338&messageID=2951168
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic