aspose 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


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 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: 10909
    
  12

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
 
 
subject: How to find the difference of two timestamps in java?
 
Similar Threads
How to pass a long in ...Long ll = Long.valueOf(3L);//gives
string to timestamp
Working with SimpleDateFormat and DAte classes
Accessing a static method with the local variable of java.text.SimpleDateFormat by multiple threads