This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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


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: 11858
    
  18

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: How to find the difference of two timestamps in java?
 
It's not a secret anymore!