File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how to get the time diffrence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to get the time diffrence" Watch "how to get the time diffrence" New topic
Author

how to get the time diffrence

pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 300
Hi,

I am entering time.

But how can i get the time difference between two times.

Eg if enter 05:00 and 19:00

then how can i get the difference between them.

Please help me.

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

Using java.text.DateFormat and java.util.Date. Using the first, convert the strings to Date objects. Then subtract the two Dates, using their getTime() methods.

This will only work of course if the Dates will be on the same actual date. Also, because of daylight savings time, the results may be a little different than you think.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Daniel Jurado
Greenhorn

Joined: Apr 28, 2009
Posts: 8


Try reading about Calendar class.
 
jQuery in Action, 2nd edition
 
subject: how to get the time diffrence
 
Similar Threads
time comparison between given periods
java.util.Date does it contain information about hours?
Date comparision in SQL from timestamp
back ground process id ??
How to convert hours,minutes,seconds to seconds