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 find the difference of two timestamps in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to find the difference of two timestamps in java?" Watch "How to find the difference of two timestamps in java?" New topic
Author

How to find the difference of two timestamps in java?

Ziya Bakan
Greenhorn

Joined: Feb 07, 2013
Posts: 13
Hi all!!!

I have a class A which includes [ String timeStamp = new SimpleDateFormat("ss S").format(new Date()); ]
and there is a class B which has a method [ private void dialogDuration(String timeStamp) ]

and dialogueDuration method includes:




And one condition is that the statement( [ String timeStamp = new SimpleDateFormat("ss S").format(new Date()); ]) wont be changed in class A. And an object of class B is created in class A so that it invokes the dialogueDuration(timeStamp) method and passes the values of timeStamps to class B.
My problem is this substraction does not work, it gives an error(cannot invoke getTime() method on the primitive type long). it gives the same kind of error also for int and String types ???

Thanks a lot in advance!!!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11305
    
  16

in the code you provided, i and j are of type "long". They are not objects. They do not have methods that you can call on them - they are just numbers.

If you want the difference, then just subtract them:

log diff = j - i;


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to find the difference of two timestamps in java?