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 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


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 "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: 11257
    
  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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to find the difference of two timestamps in java?