Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find the difference of two timestamps in java?
    primarykey
    data
    text
    <p>I have an <code>ArrayList</code> including several number of time-stamps and the aim is finding the difference of the first and the last elements of the <code>ArrayList</code>.</p> <pre><code>String a = ArrayList.get(0); String b = ArrayList.get(ArrayList.size()-1); long diff = b.getTime() - a.getTime(); </code></pre> <p>I also converted the types to int but still it gives me an error <code>The method getTime is undefined for the type String</code>.</p> <p>Additional info :</p> <p>I have a class A which includes </p> <pre><code>String timeStamp = new SimpleDateFormat("ss S").format(new Date()); </code></pre> <p>and there is a class B which has a method <code>private void dialogDuration(String timeStamp)</code></p> <p>and <code>dialogueDuration</code> method includes:</p> <pre><code>String a = timeSt.get(0); // timeSt is an ArrayList which includes all the timeStamps String b = timeSt.get(timeSt.size()-1); // This method aims finding the difference of the first and the last elements(timestamps) of the ArrayList (in seconds) long i = Long.parseLong(a); long j = Long.parseLong(b); long diff = j.getTime()- i.getTime(); System.out.println("a: " +i); System.out.println("b: " +j); </code></pre> <p>And one condition is that the statement(<code>String timeStamp = new SimpleDateFormat("ss S").format(new Date());</code>) wont be changed in class A. And an object of class B is created in class A so that it invokes the <code>dialogueDuration(timeStamp)</code> method and passes the values of time-stamps to class B.</p> <p>My problem is this subtraction does not work, it gives an error <code>cannot invoke getTime() method on the primitive type long</code>. It gives the same kind of error also for int and String types?</p> <p>Thanks a lot in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload